博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第六次java作业
阅读量:4321 次
发布时间:2019-06-06

本文共 6101 字,大约阅读时间需要 20 分钟。

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);    }}
运行结果如下:

转载于:https://www.cnblogs.com/edcf/p/11009803.html

你可能感兴趣的文章
RN全局的变量,方法,全局类,全局类方法
查看>>
安装scikit-learn
查看>>
FOJ Problem 2261 浪里个浪
查看>>
Shel脚本学习—反引号、单引号、双引号区别与联系
查看>>
Spring Boot 2 实践记录之 组合注解原理
查看>>
互联网金融爬虫怎么写-第一课 p2p网贷爬虫(XPath入门)
查看>>
语义化的理解?
查看>>
多线程学习(十)
查看>>
gnu
查看>>
SQL注入之绕过WAF和Filter
查看>>
jquery validate使用方法
查看>>
DataNode 工作机制
查看>>
windows系统下安装MySQL
查看>>
错误提示总结
查看>>
实验二+070+胡阳洋
查看>>
Linux IPC实践(3) --具名FIFO
查看>>
Qt之模拟时钟
查看>>
第一次接触安卓--记于2015.8.21
查看>>
(转)在分层架构下寻找java web漏洞
查看>>
mac下多线程实现处理
查看>>