標籤:java
2.import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.Menu;import java.awt.MenuBar;import java.awt.MenuItem;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JTextArea;public class Test {public static void main (String[] args){JFrame test= new JFrame();test.setLayout(new GridLayout(2,1));final Menu menu1 = new Menu("檔案");final Menu menu2 = new Menu("編輯");final Menu menu3 = new Menu("協助");MenuBar menubar = new MenuBar();menubar.add(menu1);menubar.add(menu2);menubar.add(menu3);test.setMenuBar(menubar);JPanel pan1 = new JPanel(new FlowLayout());String font[] = {"宋體","啊杜體","向陽體","帥帥體","鵬程體"};String fontSize[] = {"12","24","36","48", "72"};final JComboBox cb1 = new JComboBox(font);final JComboBox cb2 = new JComboBox(fontSize);JCheckBox kb1 = new JCheckBox("粗體");JCheckBox kb2 = new JCheckBox("斜體");JRadioButton rb1 = new JRadioButton("紅", true);JRadioButton rb2 = new JRadioButton("綠");JRadioButton rb3 = new JRadioButton("藍");pan1.add(cb1);pan1.add(cb2);pan1.add(kb1);pan1.add(kb2);pan1.add(rb1);pan1.add(rb2);pan1.add(rb3);test.add(pan1);JTextArea text1 = new JTextArea("Welcome 歡迎",35,25);test.add(text1);test.setVisible(true);test.pack();}}
那些年,一起學的Java 9-2