PushMe(交互式)
生活随笔
收集整理的這篇文章主要介紹了
PushMe(交互式)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
??????? 一個簡單的交互式圖形。
運行結果:
?
代碼:
1 import java.awt.*;2 import javax.swing.*;
3 import java.awt.event.*;
4
5 public class push
6 {
7 public static void main(String[] args)
8 {
9 new PushMe();//創建PushMe對象
10 }
11 }
12
13 class PushMe extends JFrame implements ActionListener
14 {
15 //JTextField類,該類有個構造函數,接受一個整數作為參數,指定文本域長度
16 private JTextField myTextField = new JTextField(15);
17 private JButton myButton = new JButton("please push me");
18 /*JLabel類的構造函數有兩個參數:待顯示文本和一個決定文本排列方式的整數值
19 * ——0,1,2依次表示左中右,在方法中可以使用預定義的常量,即Label.LEFT,
20 * Label.CENTER 和 Label.RIGHT。
21 */
22 private JLabel myLabel = new JLabel("Enter sth and push",JLabel.RIGHT);
23
24 public PushMe()
25 {
26 setTitle("Push Me");
27 setLayout(new FlowLayout());
28 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
29 setSize(200,120);
30 setLocation(400,300);
31 add(myTextField);
32 add(myButton);
33 add(myLabel);
34 myButton.addActionListener(this);
35 setVisible(true);
36 }
37 public void actionPerformed(ActionEvent e)
38 {
39 String myText;
40 myText = myTextField.getText();
41 myLabel.setText("you entered: "+myText);
42 }
43 }
?
轉載于:https://www.cnblogs.com/HpuAcmer/archive/2012/03/03/2378708.html
總結
以上是生活随笔為你收集整理的PushMe(交互式)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows Phone 7开发,进度
- 下一篇: GNU make manual 翻译(