java吧 关注:1,252,438贴子:12,737,779
  • 2回复贴,共1

50行代码 求解

只看楼主收藏回复

//<applet code=Test.class width=300 height=200></applet>
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
private JTextField text;
private JButton button1, button2, button3, exit_button;
private JPanel panel;
public Test(){
//Container con =getContentPane();
text = new JTextField(10);
button1 = new JButton("刘德华");
button2 = new JButton("张学友");
button3 = new JButton("蔡依林");
exit_button = new JButton("退 出");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
exit_button.addActionListener(this);
panel = new JPanel();
panel.add(button1);
panel.add(button2);
panel.add(button3);
this.setLayout(new FlowLayout());
this.add(text);
this.add(panel);
this.add(exit_button);
this.setSize(300, 200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if (e.getSource() == exit_button)
{
System.exit(0);
}
else
{
text.setText(e.getActionCommand());
}
}
public static void main(String args[]){
new Test();
}
}


IP属地:山东1楼2017-07-28 20:49回复
    一个小程序,简单的实现了点击某个按钮,该按钮上的字就显示在文本框内,是个小作业,但是莫名其妙的有很多错误信息,而且退出的按钮不起作用,初学者看不明白问题在哪里,求大神帮忙


    IP属地:山东2楼2017-07-28 20:50
    回复
      没有朋友帮忙看看么


      IP属地:山东3楼2017-07-29 09:24
      回复