1、制作一个如图所示的界面(使用FlowLayout布局),不要求实现功能。(图略)程序如下:
package WindowBuilder;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.EmptyBorder;import java.util.Date;import java.awt.Window.Type;import java.awt.Dialog.ModalExclusionType;public class MyClock extends JFrame { private JPanel contentPane; private JTextField textField; private JTextField textField_1; private JTextField textField_2; private JTextField textField_3; private JTextField textField_4; private JTextField textField_5; Date date=new Date(); String s1=String.format("%tH", date); String s2=String.format("%tM", date); String s3=String.format("%tS", date); public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { MyClock frame = new MyClock(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public MyClock() { setBackground(Color.GREEN); setAlwaysOnTop(true); setModalExclusionType(ModalExclusionType.TOOLKIT_EXCLUDE); setType(Type.UTILITY); setForeground(Color.GREEN); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 359, 337); contentPane = new JPanel(); contentPane.setForeground(Color.GREEN); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); JLabel label = new JLabel("\u5F53\u524D\u65F6\u95F4\uFF1A"); contentPane.add(label); textField = new JTextField(); textField.setEditable(false); textField.setHorizontalAlignment(SwingConstants.CENTER); contentPane.add(textField); textField.setColumns(5); textField.setText(s1); JLabel label_1 = new JLabel("\u65F6"); contentPane.add(label_1); textField_1 = new JTextField(); textField_1.setEditable(false); textField_1.setHorizontalAlignment(SwingConstants.CENTER); contentPane.add(textField_1); textField_1.setColumns(5); textField_1.setText(s2); JLabel label_2 = new JLabel("\u5206"); contentPane.add(label_2); textField_2 = new JTextField(); textField_2.setEditable(false); textField_2.setHorizontalAlignment(SwingConstants.CENTER); contentPane.add(textField_2); textField_2.setColumns(5); textField_2.setText(s3); JLabel label_3 = new JLabel("\u79D2"); contentPane.add(label_3); JLabel label_5 = new JLabel("\u95F9\u949F\u65F6\u95F4\uFF1A"); contentPane.add(label_5); textField_3 = new JTextField(); contentPane.add(textField_3); textField_3.setColumns(5); JLabel label_6 = new JLabel("\u65F6"); contentPane.add(label_6); textField_4 = new JTextField(); contentPane.add(textField_4); textField_4.setColumns(5); JLabel label_7 = new JLabel("\u5206"); contentPane.add(label_7); textField_5 = new JTextField(); contentPane.add(textField_5); textField_5.setColumns(5); JLabel label_8 = new JLabel("\u79D2"); contentPane.add(label_8); JLabel label_9 = new JLabel("\u95F9\u949F\u8BBE\u7F6E\uFF1A"); contentPane.add(label_9); JButton button = new JButton("\u5F00"); contentPane.add(button); JButton button_1 = new JButton("\u5173"); contentPane.add(button_1); JLabel label_4 = new JLabel(""); contentPane.add(label_4); }}
2、设计一个用标签、文本行与按钮来登录的界面(用GridLayout布局方式)。如图所示。(图略)程序如下:
package WindowBuilder;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.EmptyBorder;public class Identfiant extends JFrame { private JPanel contentPane; private JTextField textField; private JPasswordField passwordField; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Identfiant frame = new Identfiant(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public Identfiant() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(new GridLayout(2, 1, 0, 0)); JPanel panel = new JPanel(); contentPane.add(panel); panel.setLayout(new GridLayout(2, 2, 0, 0)); JLabel label = new JLabel("\u7528\u6237\u540D\uFF1A"); label.setHorizontalAlignment(SwingConstants.CENTER); panel.add(label); textField = new JTextField(); panel.add(textField); textField.setColumns(10); JLabel label_1 = new JLabel("\u53E3\u4EE4\uFF1A"); label_1.setHorizontalAlignment(SwingConstants.CENTER); panel.add(label_1); passwordField = new JPasswordField(); panel.add(passwordField); JPanel panel_1 = new JPanel(); contentPane.add(panel_1); panel_1.setLayout(null); JButton button = new JButton("\u786E\u5B9A"); button.setBounds(0, 55, 207, 61); panel_1.add(button); JButton button_1 = new JButton("\u53D6\u6D88"); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { } }); button_1.setBounds(217, 56, 197, 60); panel_1.add(button_1); }}