原程序是两个按钮的事件处理,即按BUTTON A标签出现文本XXX,按BUTTON B标签出现文本YYY
现在我改写成三个按钮
但是编译过了,就是不能执行,请各位指点一下 分数不多,只能放20了,在这谢谢了
代码如下 import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyFirstWindow extends JFrame implements ActionListener{//ActionListener 监听器
private static final String MYFIRST= "My First Window ";
private static final String CONGRUATULATIONS= "Congratulations ";
private static final String THANKS= "Thanks for your using ";
private String message=MYFIRST;
private JPanel counterPanel;
private JButton counterButton1;
private JButton counterButton2;
private JButton counterButton3;
private JLabel counterLabel;
public MyFirstWindow(){
super( "My First Window ");
counterLabel=new JLabel(message,SwingConstants.SOUTH);
counterButton1=new JButton( "My First Window ");
counterButton2=new JButton( "Congratulations ");
counterButton3=new JButton( "Thanks For your using ");
counterButton1.addActionListener(this);
counterButton2.addActionListener(this);
counterButton3.addActionListener(this);
counterPanel.add(counterLabel,BorderLayout.NORTH);
counterPanel.add(counterButton1,BorderLayout.WEST);
counterPanel.add(counterButton2,BorderLayout.CENTER);
counterPanel.add(counterButton3,BorderLayout.EAST);
getContentPane().add(counterPanel);//
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(message.equals(MYFIRST)){
message=MYFIRST;
} if(message.equals(CONGRUATULATIONS)){ message=CONGRUATULATIONS;
}
if(message.equals(THANKS)){
message=THANKS;
}
counterLabel.setText(message);
}
public static void main(final String[] args)
{final MyFirstWindow app=new MyFirstWindow();
}
}
现在我改写成三个按钮
但是编译过了,就是不能执行,请各位指点一下 分数不多,只能放20了,在这谢谢了
代码如下 import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyFirstWindow extends JFrame implements ActionListener{//ActionListener 监听器
private static final String MYFIRST= "My First Window ";
private static final String CONGRUATULATIONS= "Congratulations ";
private static final String THANKS= "Thanks for your using ";
private String message=MYFIRST;
private JPanel counterPanel;
private JButton counterButton1;
private JButton counterButton2;
private JButton counterButton3;
private JLabel counterLabel;
public MyFirstWindow(){
super( "My First Window ");
counterLabel=new JLabel(message,SwingConstants.SOUTH);
counterButton1=new JButton( "My First Window ");
counterButton2=new JButton( "Congratulations ");
counterButton3=new JButton( "Thanks For your using ");
counterButton1.addActionListener(this);
counterButton2.addActionListener(this);
counterButton3.addActionListener(this);
counterPanel.add(counterLabel,BorderLayout.NORTH);
counterPanel.add(counterButton1,BorderLayout.WEST);
counterPanel.add(counterButton2,BorderLayout.CENTER);
counterPanel.add(counterButton3,BorderLayout.EAST);
getContentPane().add(counterPanel);//
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(message.equals(MYFIRST)){
message=MYFIRST;
} if(message.equals(CONGRUATULATIONS)){ message=CONGRUATULATIONS;
}
if(message.equals(THANKS)){
message=THANKS;
}
counterLabel.setText(message);
}
public static void main(final String[] args)
{final MyFirstWindow app=new MyFirstWindow();
}
}
解决方案 »
- double*double问题
- 请教如何用java 分辨图像是否变化
- 关于Java的静态变量
- 背景问题,实在不好意思麻烦大家了。
- 脚本放置的问题……
- 字符替换问题
- 这句话URL url=new URL(new URL("http://www.abc.com")"/java/intro/")怎么理解?
- 我現在用PB+SQLSERVER做企業數據庫開發,想學JAVA,不知該如何下手,應該從哪里開始?(我的目標還是數據庫開發)
- 请问怎么样才能在两个组串比较的时候对大小写不敏感呢?
- query 怎么将datatable 返回到后台并导出excel
- 急+在线.jar打包问题
- 怎样得到一个线程产生的随机数
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame implements ActionListener{//ActionListener 监听器
private static final String MYFIRST= "My First Window ";
private static final String CONGRUATULATIONS= "Congratulations ";
private static final String THANKS= "Thanks for your using ";
private String message=MYFIRST;
private JPanel counterPanel;
private JButton counterButton1;
private JButton counterButton2;
private JButton counterButton3;
private JLabel counterLabel;
public Test(){
super( "My First Window ");
counterLabel=new JLabel(message,SwingConstants.CENTER);
counterButton1=new JButton( "My First Window ");
counterButton2=new JButton( "Congratulations ");
counterButton3=new JButton( "Thanks For your using ");
counterButton1.addActionListener(this);
counterButton2.addActionListener(this);
counterButton3.addActionListener(this);
counterPanel=new JPanel();//增加此句
counterPanel.add(counterLabel,BorderLayout.NORTH);
counterPanel.add(counterButton1,BorderLayout.WEST);
counterPanel.add(counterButton2,BorderLayout.CENTER);
counterPanel.add(counterButton3,BorderLayout.EAST);
getContentPane().add(counterPanel);//
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e){
message=((JButton)e.getSource()).getText();
if(message.equals(MYFIRST)){
message=MYFIRST;
}
if(message.equals(CONGRUATULATIONS)){
message=CONGRUATULATIONS;
}
if(message.equals(THANKS)){
message=THANKS;
}
counterLabel.setText(message);
}
public static void main(final String[] args)
{ Test app=new Test();
}
}