不多说,代码很龊,匿名类响应
import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; class MyJDialog extends JDialog { public MyJDialog(MyFrame frame1) { super(frame1, "JDialog窗体", true); Panel myPanel = new Panel(); myPanel.add(new JLabel("这是一个对话框")); this.setBounds(120, 120, 100, 100); this.add(myPanel); } } public class MyFrame extends JFrame { public MyFrame() { setVisible(true); setBounds(100, 200, 200, 200); setDefaultCloseOperation(EXIT_ON_CLOSE); Panel myPanel2 = new Panel(); myPanel2.setLayout(null); JLabel j1 = new JLabel("这是一个JFrame窗体"); j1.setHorizontalAlignment(JLabel.CENTER); myPanel2.add(j1); JButton b1 = new JButton("弹出对话框"); b1.setBounds(10, 10, 100, 21); b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub new MyJDialog(MyFrame.this).setVisible(true); } }); myPanel2.add(b1); this.add(myPanel2); } public static void main(String[] args) { new MyFrame(); } }Java Swing3-MyDialog的基本实现
内容版权声明:除非注明,否则皆为本站原创文章。