import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JFtest implements ActionListener{
static final Frame JF = null;
public static void main(String args[]) {
JFrame JF = new JFrame("Test");
JButton btn = new JButton("Press me");
btn.addActionListener(new JFtest());
JF.setLayout(new FlowLayout());
JF.add(btn);
JF.setSize(200, 100);
JF.setVisible(true);
}
void newdialog() {
JDialog jd = new JDialog(JF, "对话框", false);
JPanel jp = new JPanel();
jp.setLayout(new GridLayout(1, 2));
JButton jb1 = new JButton("Yes");
JButton jb2 = new JButton("No");
jp.add(jb1);
jp.add(jb2);
jb1.addActionListener(new BtnHandler1());
jb2.addActionListener(new BtnHandler2());
jd.add(new JLabel("你喜欢Java吗?"), "Center");
jd.add(jp, "South");
jd.setBounds(150, 200, 200, 100);
jd.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
newdialog();
}
}
class BtnHandler1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
JDialog jd = new JDialog(JFtest.JF, "对话框", false);
jd.add(new JLabel("好好学习,天天向上!"), "Center");
jd.setBounds(150, 200, 200, 100);
jd.setVisible(true);
}
}
class BtnHandler2 implements ActionListener {
public void actionPerformed(ActionEvent e) {
JDialog jd = new JDialog(JFtest.JF, "对话框", false);
jd.add(new JLabel("不喜欢也得把学分修到呀"), "Center");
jd.setBounds(150, 200, 200, 100);
jd.setVisible(true);
}
}
Java弹出对话框小程序
猜你喜欢
转载自blog.csdn.net/Miracle1203/article/details/103699289
今日推荐
周排行