import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class guiagg implements ActionListener,ItemListener,ListSelectionListener{
         JRadioButton button_yellow, button_red,button_green;
         JLabel jl;
         JButton jb_change, jb_exit;
         JCheckBox jchk_bold, jchk_italic;
         JComboBox jcbo;
         JList jlst;
      public guiagg(){
        JFrame jf=new JFrame();
        jf.setSize(800,400);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jl=new JLabel("",JLabel.CENTER);
        jl.setFont(new Font("",Font.BOLD,40));
        jl.setText("ǶѧJAVA");
        jb_change=new JButton("");
        jb_exit=new JButton("˳");        
        jb_change.addActionListener(this);
        jb_exit.addActionListener(this);        
        button_yellow=new JRadioButton("");button_red=new JRadioButton("");
        button_green=new JRadioButton("");ButtonGroup bg=new ButtonGroup();
        bg.add(button_yellow);bg.add(button_red);bg.add(button_green);
        button_yellow.addActionListener(this);button_red.addActionListener(this);
        button_green.addActionListener(this);
        jchk_bold=new JCheckBox("Ӵ");jchk_italic=new JCheckBox("б");
        jchk_bold.addActionListener(this);jchk_italic.addActionListener(this);
        jcbo=new JComboBox();
        jcbo.addItem("12");jcbo.addItem("28");jcbo.addItem("36");
        jcbo.addItem("48");jcbo.addItemListener(this);
        jlst=new JList();Vector vv=new Vector();
        vv.add("");vv.add("");vv.add("");jlst.setListData(vv);
        jlst.addListSelectionListener(this);
        JPanel jp=new JPanel(new BorderLayout());
        JPanel jpc=new JPanel();
        JPanel jp1=new JPanel(new GridLayout(4,1));
        JPanel jpl1=new JPanel();JPanel jpl2=new JPanel();
        JPanel jpl3=new JPanel();JPanel jp2=new JPanel();
        JPanel jp3=new JPanel ();
        JPanel jps=new JPanel(new FlowLayout(FlowLayout.LEFT,40,10));
        FlowLayout fl=new FlowLayout(FlowLayout.LEFT);
        jpl1.setLayout(fl);jpl2.setLayout(fl);
        jpl3.setLayout(fl);jp2.setLayout(fl);
        jpl1.add(new JLabel("ѡǰɫ:"));
        jpl1.add(button_yellow);jpl1.add(button_red);jpl1.add(button_green);
        jpl2.add(new JLabel("ѡ:"));
        jpl2.add(jchk_bold);  jpl2.add(jchk_italic);
        jpl3.add(new JLabel("ѡֺţ"));
        jpl3.add(jcbo);  jpc.add(jl);  jp1.add(jpl1);  jp1.add(jpl2);  jp1.add(jpl3);
   jp2.add(new JLabel("ѡ壺"));
   jp2.add(jlst);  jp3.add(jb_change);  jp3.add(jb_exit);
   jps.add(jp1);  jps.add(jp2);  jps.add(jp3);
   jp.add(jpc,BorderLayout.CENTER);  jp.add(jps,BorderLayout.SOUTH);
   jf.getContentPane().add(jp);  jf.setVisible(true);
}
public void itemStateChanged(ItemEvent e){//б
   fontset();}
public void valueChanged(ListSelectionEvent e){//б
   fontset();}
public void actionPerformed(ActionEvent e ){//ѡťѡťť
  if(e.getSource()==button_yellow){
     jl.setForeground(Color.yellow);  }
  if(e.getSource()==button_red){
     jl.setForeground(Color.red);  }
  if(e.getSource()==button_green){
     jl.setForeground(Color.green);  }
  if(e.getSource()==jchk_bold){
     fontset();  }
  if(e.getSource()==jchk_italic) {
     fontset();}
  if(e.getSource()==jb_change){
     String str = JOptionPane.showInputDialog(":");
     jl.setText(str);}
if(e.getSource()==jb_exit){
     int jopvalue=JOptionPane.showConfirmDialog(null,"ȷҪ˳","ʾ!",JOptionPane.YES_NO_OPTION);
  if(jopvalue==JOptionPane.YES_OPTION)
   System.exit(0);  }
}
void fontset(){ //
   int fstyle=Font.PLAIN;
   if(jchk_bold.isSelected())
     fstyle=Font.PLAIN|Font.BOLD;
   if(jchk_italic.isSelected())
     fstyle=fstyle|Font.ITALIC;
   Object folst=jlst.getSelectedValue();
   String fname="";
   if(!(folst==null)){
     fname=folst.toString();   }
   Object focbo=jcbo.getSelectedItem();
   int fsize=12;
   if(!(focbo==null)){
      fsize=Integer.parseInt(focbo.toString());}    
jl.setFont(new Font (fname,fstyle,fsize));  }
public static void main (String args[]){
        new guiagg();
 }
}
