JCheckBox

package frame;

import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

public class JCheckBox1{
  public static void main(String[] args){
     JFrame f=new JFrame("JCheckBox1");
     Container contentPane=f.getContentPane();
     contentPane.setLayout(new GridLayout(2,1));
     JPanel p1=new JPanel();
     p1.setLayout(new GridLayout(5,1));
     TitledBorder b=BorderFactory.createTitledBorder("你最喜欢哪一家快餐店呢?");
     b.setTitleColor(Color.RED);
     p1.setBorder(b);
     JCheckBox c1=new JCheckBox("麦当劳");
     JCheckBox c2=new JCheckBox("肯德基");
     JCheckBox c3=new JCheckBox("21世纪");
     p1.add(c1);
     p1.add(c2);
     p1.add(c3);
     JPanel p2=new JPanel();
     p2.setLayout(new GridLayout(1,1));
     p2.setBorder(BorderFactory.createTitledBorder("以下为JCheckBox的图形示范:"));
//     JCheckBox c4=new JCheckBox("图形1",new ImageIcon(".\\icons\\Warning.gif"));
//     JCheckBox c5=new JCheckBox("图形2",new ImageIcon(".\\icons\\Warning.gif"));
     JTextArea a=new JTextArea();
//     p2.add(c4);
//     p2.add(c5);
     p2.add(a);
     contentPane.add(p1);
     contentPane.add(p2);
     f.pack();
     f.setSize(500, 400);
     f.setLocationByPlatform(false);
     f.setDefaultLookAndFeelDecorated(false);
     f.show();
    
       f.addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){
              System.exit(0);
           }
       });
  }
}

你可能感兴趣的:(java,swing,F#)