GUI 容器
窗体JFrame
package Dem0o1;
import java.awt.Container;
import javax.swing.JDialog;
import javax.swing.JLabel;
public class JDialogTest extends JDialog {
public static void main(String[] args) {
JDialog jd = new JDialog();
jd.setVisible(true);
jd.setBounds(200,300,450,350);
Container c = jd.getContentPane();
c.add(new JLabel("这是一个标签"));
}
}
面板
package Dem0o1;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class jFrameTest extends JFrame {
public jFrameTest(){
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(200,300,450,350);
Container c = getContentPane();
c.setBackground(Color.pink);
JLabel l = new JLabel("这是一个标签");
c.add(l);
c.validate();
setResizable(false);
}
public static void main(String[] args) {
new jFrameTest();
}
对话框
package Dem0o1;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class JDialogTest2 extends JDialog {
public JDialogTest2( JFrame frame) {
super(frame,"对话框标签",true);
setVisible(true);
setBounds(100,100,100,50);
}
public static void main(String[] args) {
JFrame f = new JFrame("父窗体");
f.setBounds(50,50,300,300);
Container c = f.getContentPane();
JButton btn = new JButton("弹出对话框");
c.setLayout(new FlowLayout());
c.add(btn);
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
2020080605013