import javax.swing.JApplet;
import javax.swing.*;
import java.awt.*;
public class MyApplet extends JApplet {
private JButton b1 = new JButton("button1");
private JButton b2 = new JButton("button2");
private JLabel l = new JLabel("please chose button");
public void init() {
ActionListener a1 = new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b1) {
l.setText("button b1 is press!");
}
if (e.getSource() == b2) {
l.setText("button b2 is press!");
}
}
};
b1.addActionListener(a1);
b2.addActionListener(a1);
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(b1);
p.add(b2);
setLayout(new BorderLayout());
add(p,BorderLayout.CENTER);
//add(1,BorderLayout.C);
}
}
解决方案 »
- try catch语句出错了
- 关于快速排序,他的原理是什么? 搞不明白呢。
- 符号运算中的正则表达式问题(Java中)
- JTable上显示JCheckBox,如何显示disabled
- 如何把java.util.Date 或 java.sql.Timestamp 的年份,月份,日子 分别取出来?
- 我们老师让我用java存储xml ,存储到postgreSQL中
- 收集应用JAVA程序访问 Berkeley DB 的资料!急!
- 关于字符串比较大小?下面代码有错么?????????????
- 请问http://china-programer.myrice.com为什么进不进去?
- 几个问题:
- 我是新手?从来没接触过JAVE和.NET ,不知道从拿着手希望各位大侠帮忙知道下!!
- 安装SQL2005时提示已经存在更高版本..怎么解决?
不好意思
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MyApplet extends JApplet {
private JButton b1 = new JButton("button1");
private JButton b2 = new JButton("button2");
private JLabel l = new JLabel("please chose button");
public void init() {
ActionListener a1 = new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b1) {
l.setText("button b1 is press!");
}
if (e.getSource() == b2) {
l.setText("button b2 is press!");
}
}
};
b1.addActionListener(a1);
b2.addActionListener(a1);
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(b1);
p.add(b2);
setLayout(new BorderLayout());
add(p,BorderLayout.CENTER);
//add(1,BorderLayout.C);
}
}