第六次实训作业

1 package WindowBuilder;
  2 
  3 import java.awt.*;
  4 import java.awt.event.*;
  5 import javax.swing.*;
  6 import javax.swing.border.EmptyBorder;
  7 import java.util.Date;
  8 import java.awt.Window.Type;
  9 import java.awt.Dialog.ModalExclusionType;
 10 
 11 public class MyClock extends JFrame {
 12 
 13     private JPanel contentPane;
 14     private JTextField textField;
 15     private JTextField textField_1;
 16     private JTextField textField_2;
 17     private JTextField textField_3;
 18     private JTextField textField_4;
 19     private JTextField textField_5;
 20     Date date=new Date();
 21     String s1=String.format("%tH", date);
 22     String s2=String.format("%tM", date);
 23     String s3=String.format("%tS", date);
 24     public static void main(String[] args) 
 25     {
 26         EventQueue.invokeLater(new Runnable() 
 27         {
 28             public void run() {
 29                 try {
 30                     MyClock frame = new MyClock();
 31                     frame.setVisible(true);
 32                 } catch (Exception e) {
 33                     e.printStackTrace();
 34                 }
 35             }
 36         });
 37     }
 38 
 39     /**
 40      * Create the frame.
 41      */
 42     public MyClock() {
 43         setBackground(Color.GREEN);
 44         setAlwaysOnTop(true);
 45         setModalExclusionType(ModalExclusionType.TOOLKIT_EXCLUDE);
 46         setType(Type.UTILITY);
 47         setForeground(Color.GREEN);
 48         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 49         setBounds(100, 100, 359, 337);
 50         contentPane = new JPanel();
 51         contentPane.setForeground(Color.GREEN);
 52         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
 53         setContentPane(contentPane);
 54         contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
 55         
 56         JLabel label = new JLabel("\u5F53\u524D\u65F6\u95F4\uFF1A");
 57         contentPane.add(label);
 58         
 59         textField = new JTextField();
 60         textField.setEditable(false);
 61         textField.setHorizontalAlignment(SwingConstants.CENTER);
 62         contentPane.add(textField); 
 63         textField.setColumns(5);
 64         textField.setText(s1);
 65         
 66         JLabel label_1 = new JLabel("\u65F6");
 67         contentPane.add(label_1);
 68         
 69         textField_1 = new JTextField();
 70         textField_1.setEditable(false);
 71         textField_1.setHorizontalAlignment(SwingConstants.CENTER);
 72         contentPane.add(textField_1);
 73         textField_1.setColumns(5);
 74         textField_1.setText(s2);
 75         
 76         JLabel label_2 = new JLabel("\u5206");
 77         contentPane.add(label_2);
 78         
 79         textField_2 = new JTextField();
 80         textField_2.setEditable(false);
 81         textField_2.setHorizontalAlignment(SwingConstants.CENTER);
 82         contentPane.add(textField_2);
 83         textField_2.setColumns(5);
 84         textField_2.setText(s3);
 85         
 86         JLabel label_3 = new JLabel("\u79D2");
 87         contentPane.add(label_3);
 88         
 89         JLabel label_5 = new JLabel("\u95F9\u949F\u65F6\u95F4\uFF1A");
 90         contentPane.add(label_5);
 91         
 92         textField_3 = new JTextField();
 93         contentPane.add(textField_3);
 94         textField_3.setColumns(5);
 95         
 96         JLabel label_6 = new JLabel("\u65F6");
 97         contentPane.add(label_6);
 98         
 99         textField_4 = new JTextField();
100         contentPane.add(textField_4);
101         textField_4.setColumns(5);
102         
103         JLabel label_7 = new JLabel("\u5206");
104         contentPane.add(label_7);
105         
106         textField_5 = new JTextField();
107         contentPane.add(textField_5);
108         textField_5.setColumns(5);
109         
110         JLabel label_8 = new JLabel("\u79D2");
111         contentPane.add(label_8);
112         
113         JLabel label_9 = new JLabel("\u95F9\u949F\u8BBE\u7F6E\uFF1A");
114         contentPane.add(label_9);
115         
116         JButton button = new JButton("\u5F00");
117         contentPane.add(button);
118         
119         JButton button_1 = new JButton("\u5173");
120         contentPane.add(button_1);
121         
122         JLabel label_4 = new JLabel("");
123         contentPane.add(label_4);
124     }
125 
126 }

第六次实训作业

上一篇:图形界面2


下一篇:并发编程-AQS之CountDownLatchSemaphore原理