《java編程思想》第22章 練習5

來源:互聯網
上載者:User

首先對題目意思感覺有點不太理解,看這本書的時候很多意思都感覺繞口,有些段落翻譯的不流暢。所以,簡單寫了一個仿書中來源程式的代碼,沒什麼參考意義,只是記錄。

 

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import static util.SwingConsole.*;//自己寫的,前篇有提及

public class Button extends JFrame
{
 private JButton
      b1=new JButton("Button 1"),
      b2=new JButton("Button 2"),
      b3=new JButton("Button 3");
 private JTextField txt=new JTextField(10);
 private ActionListener blisten=new ActionListener(){
  public void actionPerformed(ActionEvent e)
  {
   String name=((JButton)e.getSource()).getText();
   txt.setText(name);
  }};
 public Button()
 {
       b1.addActionListener(blisten);
       b2.addActionListener(blisten);
       b3.addActionListener(blisten);
      setLayout(new FlowLayout());
     add(b1);
     add(b2); 

     add(b3);
      add(txt);
 }
 public static void main(String[] args)
 {
      run(new Button(),200,150);
 }
}

 

 

看了下後面的練習題,後面才是關鍵,今晚早點睡,晚上想看球賽,拜仁必勝!

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.