学习GUI组件显示
使用类JButton,JLabel,JCheckBox,JRadioButton,JcomboBox来创建GUI对象。
package com.studyJava.stringStudy; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; /** * GUI展示 * @author ywf * */ public class TestJframe { public static void main(String[] args){ JButton jbtOk = new JButton("OK"); JButton jbtCancel = new JButton("cancel");//按钮 JLabel jlbName = new JLabel("Enter your name");//标签 JTextField jtfName = new JTextField("Type Name here");//文本域 JCheckBox jchkBold = new JCheckBox("Bold");//复选框 JCheckBox jchkItalic = new JCheckBox("Italic"); JRadioButton jrbRed = new JRadioButton("Red");//单选框 JRadioButton jrbYellow = new JRadioButton("Yellow"); String[] str ={"Freshman","Sophomore","Junior","Senior"}; JComboBox jcbColor = new JComboBox(str);//组合框 JPanel panel = new JPanel();//创建一个面板对象 panel.add(jbtOk); panel.add(jbtCancel); panel.add(jlbName); panel.add(jtfName); panel.add(jchkBold); panel.add(jchkItalic); panel.add(jrbRed); panel.add(jrbYellow); panel.add(jcbColor); JFrame jframe = new JFrame(); jframe.add(panel); jframe.setSize(400, 300); jframe.setLocation(400, 300); jframe.setTitle("JAVA"); jframe.setVisible(true); jframe.setDefaultCloseOperation(jframe.EXIT_ON_CLOSE); } }