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);
}
}
解决方案 »
- java扫描图像内存
- JTable
- 想学习多线程编程java好还是C++好?
- wait和notify之间的线程通信问题
- MySQL在spring中的一个奇怪的问题
- 关于resultset的问题?
- 怎样指定文件中的内容操作呢?谢谢
- 请问javamail中的POP3协议的实现类是哪个?
- tomcat在98下怎么设置才能运行啊?~~~~~~~~~~~~~~~~~~!好急啊~~~~~~谢谢大家
- ######################怎样在树形节点上加上setToolTipText()?
- 我是新手?从来没接触过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);
}
}