62,612
社区成员
发帖
与我相关
我的任务
分享
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class t2 extends JPanel {
JButton button ;
public t2() {
button = new JButton("Open");
setLayout(new FlowLayout());
add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog dialog = new dialog(new Frame(), true);
dialog.setLocationRelativeTo(this);
}
});
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("TimeTabling System");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent newContentPane = new t2();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
class dialog extends JDialog{
JButton OKBtn, CancelBtn;
public dialog(Frame parent, boolean modal){
super(parent, modal);
setLayout(new FlowLayout());
OKBtn = new JButton("OK");
CancelBtn = new JButton("CancelBtn");
add(OKBtn);
add(CancelBtn);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
pack();
setVisible(true);
}
}