import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class TestSwing extends JFrame{
public TestSwing(){
JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT,2,2));
JButton jbLeft = new JButton("left");
JButton jbCenter=new JButton("center");
JButton jbRight=new JButton("right");
jbLeft.setBackground(Color.WHITE);
jbCenter.setForeground(Color.GREEN);
jbRight.setToolTipText("This is Right button");
p1.add(jbLeft);
p1.add(jbCenter);
p1.add(jbRight);
p1.setBorder(new TitledBorder("three Button"));
Font largeFont=new Font("TimeRoman",Font.BOLD,20);
Border lineBorder=new LineBorder(Color.black,2);
JPanel p2=new JPanel(new GridLayout(1,2,5,5));
JLabel jlblRed=new JLabel("red");
JLabel jlblOrange=new JLabel("orange");
jlblRed.setForeground(Color.RED);
jlblOrange.setForeground(Color.ORANGE);
jlblRed.setFont(largeFont);
jlblOrange.setFont(largeFont);
jlblRed.setBorder(lineBorder);
jlblOrange.setBorder(lineBorder);
p2.add(jlblRed);
p2.add(jlblOrange);
p2.setBorder(new TitledBorder("Two Labaes"));
setLayout(new GridLayout(2,1,5,5));
add(p1);
add(p2);
}
public static void main(String[] args)
{
JFrame frame=new TestSwing();
frame.setTitle("TestSing");
frame.setSize(300,150);//设置框架的大小,宽300,高150
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}