zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    JSP 学习笔记1
    XML scriptlet 连接数据库
    JSP 定义行列数表单创建表格
    JSP_01
    JS创建表格完整
    04-基本的mysql语句
    03-MySql安装和基本管理
    02-数据库概述
    01-MySql的前戏
    爬虫系列
  • 原文地址:https://www.cnblogs.com/HpuAcmer/p/2378708.html
Copyright © 2011-2022 走看看