java按钮无响应_java中界面点击登录按钮没有反应

publicclassGUIimplementsActionListener{JFrameframe;JLabellabel1,label2,label3;JPanelpanel1,panel2;JButtonbutton;JTextFieldtextfield1,textfield2;publicstaticvoidmain(Strin...

public class GUI implements ActionListener {

JFrame frame;

JLabel label1,label2,label3;

JPanel panel1,panel2;

JButton button;

JTextField textfield1,textfield2;

public static void main(String[]args){

GUI gui=new GUI();

gui.go();

}

private void go() {

frame=new JFrame();

frame.setSize(300, 300);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

panel1=new JPanel();

panel1.setLocation(0, 100);

panel1.setBackground(Color.blue);

frame.getContentPane().add(BorderLayout.CENTER,panel1);

label1=new JLabel("进销存系统");

label1.setSize(100, 100);

panel1.add(label1);

panel2=new JPanel();

panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));

label2=new JLabel("用户名");

label3=new JLabel("密码");

textfield1=new JTextField(20);

textfield1=new JTextField();

textfield2=new JTextField(20);

textfield2=new JTextField();

button=new JButton("登录");

button.addActionListener(this);

panel2.add(label2);

panel2.add(textfield1);

panel2.add(label3);

panel2.add(textfield2);

panel2.add(button);

frame.getContentPane().add(BorderLayout.EAST, panel2);

Mypanel drawPanel=new Mypanel();

frame.setVisible(true);

// TODO Auto-generated method stub

}

public void actionPerformed(ActionEvent e) {

frame.repaint();

// TODO Auto-generated method stub

}

class Mypanel extends JPanel{

public void paintComponent(Graphics g){

g.setColor(Color.black);

g.fillRect(0, 0, frame.getWidth(), frame.getHeight());

}

}

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值