278083904 278083904
关注数: 15 粉丝数: 25 发帖数: 2,316 关注贴吧数: 7
java图形界面 怎么文本框要用鼠标点一下才出来 import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*; public class BuildMaze extends JFrame implements ActionListener{private JButton random,Return,display,choice;private ImageIcon icon;private JPanel panel,northpanel,centerpanel,southpanel;private JLabel label,label1;private JTextField txt1,txt2;   private int num1,num2;   private JRadioButton[] one,zeor;   private JTextField[][] text;public BuildMaze(){Init();        this.setMinimumSize(new Dimension(700,600));   setLocation(200,200);      this.setTitle("建立迷宫"); this.add(panel);   this.pack();   this.setVisible(true);   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void Init(){icon = new ImageIcon ("111.gif"); panel = new JPanel(); northpanel = new JPanel();centerpanel = new JPanel();southpanel = new JPanel();panel.setLayout(new BorderLayout());   random = new JButton("自动建立",icon);   Return = new JButton("返回菜单",icon);   display = new JButton ("显示迷宫",icon);   choice = new JButton("确定");       label = new JLabel("请输入迷宫矩阵的行数和列数:");   txt1 = new JTextField(2);   txt2 = new JTextField(2);        panel.setBackground (Color.white);    southpanel.add(random);   southpanel.add(Return);   northpanel.add(label);   northpanel.add(txt1);   northpanel.add(txt2);   northpanel.add(choice);   southpanel.add(display);;      txt1.addActionListener (this);   txt2.addActionListener (this);   random.addActionListener (this);   Return.addActionListener (this);   display.addActionListener (this);   choice.addActionListener (this);   panel.add(northpanel,BorderLayout.NORTH);   panel.add(centerpanel,BorderLayout.CENTER);   panel.add(southpanel,BorderLayout.SOUTH);}public void actionPerformed (ActionEvent event){    if (event.getSource()==random) System.out.println("b"); else if (event.getSource()==display) { JFrame displayMaze = new DisplayMaze();}else if (event.getSource()==choice){ String text1 = txt1.getText(); String text2 = txt2.getText(); num1 = Integer.parseInt (text1); num2 = Integer.parseInt (text2); text = new JTextField[num1][num2]; //centerpanel.removeAll();   centerpanel.setLayout (null);   centerpanel.setBackground(Color.black); for(int i=0;i<num1;i++) { for(int j=0;j<num2;j++)   { text[i][j] = new JTextField(); text[i][j].setBounds(50+j*50,50+i*40,40,30); text[i][j].setVisible(); centerpanel.add(text[i][j]); } }    centerpanel.validate(); panel.add(centerpanel,BorderLayout.CENTER); panel.validate(); } else if(event.getSource()==Return){ BuildMaze.this.setVisible(false);BuildMaze.this.dispose();JFrame Maze = new MazeTwo();} else{}}    }
首页 1 2 3 4 5 下一页