大学时,学过JApplet/Applet,很久没用过了.
package three.day.frame; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.ButtonGroup; import javax.swing.JApplet; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JRadioButton; public class JAppletDemo01 extends JApplet implements ItemListener,ActionListener { int r=0,g=0,b=0; int fSize = 16; Font f; Container ctp = this.getContentPane(); JLabel lb = new JLabel("请选择"); JCheckBox cb1,cb2,cb3; JRadioButton r1,r2,r3; ButtonGroup bg = new ButtonGroup(); public void init() { ctp.setLayout(new FlowLayout()); cb1 = new JCheckBox("红色",false); cb1.addItemListener(this); ctp.add(cb1); cb2 = new JCheckBox("绿色",false); cb2.addItemListener(this); ctp.add(cb2); cb3 = new JCheckBox("蓝色",false); cb3.addItemListener(this); ctp.add(cb3); r1 = new JRadioButton("16",false); r1.addActionListener(this); ctp.add(r1); r2 = new JRadioButton("20",false); r2.addActionListener(this); ctp.add(r2); r3 = new JRadioButton("28",false); r3.addActionListener(this); ctp.add(r3); bg.add(r1); bg.add(r2); bg.add(r3); ctp.add(lb); } @Override public void actionPerformed(ActionEvent e) { String rbt = e.getActionCommand(); if("16"==rbt) { fSize = 16; } else if("20"==rbt) { fSize = 20; } else { fSize = 28; } f = new Font("宋体",Font.BOLD,fSize); lb.setFont(f); lb.setForeground(new Color(r,g,b)); } @Override public void itemStateChanged(ItemEvent e) { JCheckBox cbx = (JCheckBox)e.getItem(); if("红色"==cbx.getText()) { if(e.SELECTED==e.getStateChange()) { r = 255; } else { r = 0; } } if("绿色"==cbx.getText()) { if(e.SELECTED==e.getStateChange()) { g = 255; } else { g = 0; } } if("蓝色"==cbx.getText()) { if(e.SELECTED==e.getStateChange()) { b = 255; } else { b = 0; } } f = new Font("宋体",Font.BOLD,fSize); lb.setFont(f); lb.setForeground(new Color(r,g,b)); } }
Linker From : http://blog.csdn.net/QQ1130141391/article/details/12246563
JavaSwing图形界面编程之JApplet(二)~JavaSwing图形界面编程之JApplet(四)均可以从上面链接获取.