JAVA 程式語言入門 (II).  版面配置  事件驅動  Ch14_01.java 1. import javax.swing.*; 2. import java.awt.*; 3. class Ch14_01 4. { 5. public static void main(String.

Slides:



Advertisements
Similar presentations
Layouts and Graphics. component - container - layout Un Container contiene [0 o +] Components Il Layout specifica come i Components sono disposti nel.
Advertisements

1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Introduction to Swing Components Chapter 14. Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.
Unit 121 A layout manager is an object that determines the manner in which components are arranged in a container. Each layout manager implements one of.
GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
ITK:P1 Lektion 6 Den abstrakta datatypen kö DSV Peter Mozelius.
Graphical User Interfaces
JAVA1 1. JFrame. JAVA2 JApplet import java.awt.*; import java.awt.event.*; import javax.swing.*; public class HerhalingAppletH10 extends JApplet implements.
ตัวอย่างการพัฒนา ระบบงาน. 2 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SignInWindow extends JFrame { JPanel panel;
Computer Science 209 Images and GUIs. Working with Java Colors The class java.awt.Color includes constants, such as Color.red, for some commonly used.
Web Design & Development Lecture 19. Java Graphics 2.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 21.
Graphics and event-driven programs Learning objectives By the end of this lecture you should be able to: identify and use some of the common components.
Page w16.1 – Spring 2010Steffen Vissing Andersen SDJ I1 subjects, Spring 2010 Agenda – Week 16, 2010 GUI.
1 MSPEL Lektion 3 DSV Peter Mozelius Grafik och spel i Java applets.
ITK:P1 Lektion 2 Klassarv, polymorfism och grafiska komponenter DSV Peter Mozelius.
Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
Graphical User Interfaces Java’s AWT and Swing APIs.
Graphical User Interfaces (Part IV)
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Examples. // A simple Frame with Rectangle Inside import java.awt.*; import javax.swing.*; import java.awt.geom.*; // For Shapes class rectComponent extends.
Drawing in a frame – Java GUI
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
Graphical User Interface Bonus slides Interaction Between Components & Drawing.
Bar Graph Design. Left-side/Right-side mechanical processing creative, abstract reasoning.
Swing: the art of the GUI COMP204, Bernhard Pfahringer.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Övning 5. Repetition klasser class Rektangel { private static int antal = 0; private double längd; private double bredd; public Rektangel(double l, double.
Swing 井民全 製作
Java Swing Comes from originallyhttp://debut.cis.nctu.edu.tw/~ching/
Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington.
Introduction to Java Programming Lecture 15 Objects and Classes.
24-6 設定開始與結束場景中的 程式 最後我們要替這個遊戲收個尾, 幫它把開始 的等待畫面跟結束畫面處理一下。
如何建立一個 swing 元件 -- 以 ImageComponent 為例 井民全. Step 1: 繼承 javax.swing.JComponent 要將你的元件秀在 frame 中. 元件必須是 Jcomponent 的一種. javax.swing.JComponent 你的元件 class.
Hung-Hsiang WuWindows Processing Design1 Chapter 3 基本觀念 變數宣告與型態 特殊運算子符號 字串與數值的轉換 類別與物件的觀念 建立新的專案 WinMain 程式進入點 Include Header File.
Introduction to Java Programming Lecture 19 JAVA GUI Programming.
JAVA 程式設計與資料結構 第八章 GUI Introduction I. GUI  使用 java.swing 的 package 來設計視窗介 面,我們稱之為 Graphic User Interface(GUI) 。  在設計 GUI 的時候,需要 import javax.swing.*;
6-2 認識元件庫與內建元件庫 Flash 的元件庫分兩種, 一種是每個動畫專 屬的元件庫 (Library) ;另一種則是內建元 件庫 (Common Libraries), 兩者皆可透過 『視窗』功能表來開啟, 以下即為您說明。
Hung-Hsiang WuWindows Processing Design1 Chapter 4 簡單視窗程式 表單與標籤的屬性 按鈕與編輯的屬性 設計簡單的應用程式 表單常用事件 一般鍵盤及滑鼠常見的事件 表單視窗間的呼叫 表單間資料傳送應用 專案選擇設定.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
安全性管理員 Java 學習手冊 p.p SecurityManager 觀念  Java Application 的系統資源存取權限的設 定  可以由 SecurityManager 完全控制 如 : 檔案系統, Thread, 執行外部 process, 網路存取 一旦 Security.
程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0 程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0許翠婷
MFC Example 游子宜.
OBJECTS AND CLASSES Outline Reference Variables and Reference Types Primitive Types and Reference Types Static Variable, Constants,
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
CS Lecture 01 Frames and Components and events Lynda Thomas
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Ch17 專案 (1)- 賽馬 物件導向系統實務. 2015/12/52 五匹馬賽跑 _DOS 版 1/2 1.class Horse5_DOS 2.{ 3.static Horse[] h = new Horse[5]; 4.static Thread[] t = new Thread[h.length];
Ch15 簡單計算機 物件導向系統實務. Ch22_Main.java import javax.swing.*; import java.awt.*; import java.awt.event.*; class Ch22_Main { public static void main(String.
Easy Talking!! 網路聊天室 組員 : 4970E002 劉浩文 4970E074 程均勤 4970E055 陳典杰.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
AWT  認識 AWT  容器與版面配置  事件處理  AWT 元件使用. 認識 AWT  GUI ( graphical user interface)  AWT(Abstract Window Toolkits)  Package java.awt.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
Graphical User Interfaces
動態版面 建國科技大學 資管系 饒瑞佶 2017/7.
滑動 建國科技大學 資管系 饒瑞佶 2013/4 V1 2015/5 V2.
Graphical User Interface
Presentation transcript:

JAVA 程式語言入門 (II)

 版面配置  事件驅動

 Ch14_01.java 1. import javax.swing.*; 2. import java.awt.*; 3. class Ch14_01 4. { 5. public static void main(String [] args) 6. { 7. Ch14_Win app = new Ch14_Win(" 視窗程式 Ch14_01"); 8. app.setDefaultCloseOperation(app.EXIT_ON_CLOSE); 9. app.setSize(200, 300); 10. app.setVisible(true); 11. } 12. }

1. import javax.swing.*; 2. import java.awt.*; 3. class Ch14_Win extends JFrame 4. { 5. // 建構子 6. Ch14_Win(String title) 7. { 8. super(title); 9. //Step 1: 取得可放置元件的內容版面 10. Container c = getContentPane(); 11. //Step 2: 宣告加入視窗的按鈕元件 17. JButton b1 = new JButton("b1"); 18. //Step 3: 將元件加入面版 19. c.add(b1); 20. //Step 4: 處理元件動作 21. } 22. }

 import javax.swing.*;  import java.awt.*;  class Ch14_Win extends JFrame  {  // 建構子  Ch14_Win(String title)  {  super(title);  //Step 1: 取得可放置元件的 內容版面  Container c = getContentPane();  c.setLayout(new FlowLayout(FlowLayout.LEFT));  //Step 1.1: 加入佈局管理員  //(1) 外框佈局 BorderLayout  JPanel p1 = new JPanel();  p1.setLayout(new BorderLayout(5,10));  //(2) 循序佈局 FlowLayout  JPanel p2 = new JPanel();  p2.setLayout(new FlowLayout(FlowLayout.LEFT, 5,10));  //(3) 格狀佈局 GridLayout  JPanel p3 = new JPanel();  p3.setLayout(new GridLayout(2,3,5,10)); 

 //Step 2: 宣告加入視窗的按鈕元件  JButton b1_1 = new JButton("b1_1");  JButton b1_2 = new JButton("b1_2");  JButton b1_3 = new JButton("b1_3");  JButton b1_4 = new JButton("b1_4");  JButton b1_5 = new JButton("b1_5");  JButton b2_1 = new JButton("b2_1");  JButton b2_2 = new JButton("b2_2");  JButton b2_3 = new JButton("b2_3");  JButton b2_4 = new JButton("b2_4");  JButton b2_5 = new JButton("b2_5");  JButton b3_1 = new JButton("b3_1");  JButton b3_2 = new JButton("b3_2");  JButton b3_3 = new JButton("b3_3");  JButton b3_4 = new JButton("b3_4");  JButton b3_5 = new JButton("b3_5");  //Step 3: 將元件加入面版  p1.add(b1_1, BorderLayout.EAST);  p1.add(b1_2, BorderLayout.WEST);  p1.add(b1_3, BorderLayout.NORTH);  p1.add(b1_4, BorderLayout.SOUTH);  p1.add(b1_5, BorderLayout.CENTER);   p2.add(b2_1);  p2.add(b2_2);  p2.add(b2_3);  p2.add(b2_4);  p2.add(b2_5);  p3.add(b3_1);  p3.add(b3_2);  p3.add(b3_3);  p3.add(b3_4);  p3.add(b3_5);  c.add(p1);  c.add(p2);  c.add(p3);  //Step 4: 處理元件動作  }   }

 方法 1  import javax.swing.*;  import java.awt.*;  import java.awt.event.*;  class Ch14_Win extends JFrame implements ActionListener  {  int num = 0;  String s1 = " 你按了幾次 : " ;  JLabel l1 = new JLabel(s1);  // 建構子  Ch14_Win(String title)  {  super(title);  //Step 1: 取得可放置元件的內容版 面  Container c = getContentPane();  c.setLayout(new FlowLayout());  //Step 2: 宣告加入視窗的按鈕元件  JButton b1 = new JButton("b1");  b1.addActionListener(this);  //Step 3: 將元件加入面版  c.add(b1);  c.add(l1);  }  //Step 4: 處理元件動作  public void actionPerformed(ActionEvent evt)  {  num++;  l1.setText(s1 + num); // 重設文字 內容  }   }

 import javax.swing.*;  import java.awt.*;  import java.awt.event.*;  class Ch14_Win extends JFrame  {  int num = 0;  String s1 = " 你按了幾次 : " ;  JLabel l1 = new JLabel(s1);  // 建構子  Ch14_Win(String title)  {  super(title);  //Step 1: 取得可放置元件的內容 版面  Container c = getContentPane();  c.setLayout(new FlowLayout());  //Step 2: 宣告加入視窗的按鈕元 件 +Step 4: 處理元件動作  JButton b1 = new JButton("b1");  ActionListener a1 = new ActionListener()  {  public void actionPerformed(ActionEvent e)  {  num++;  l1.setText(s1 + num); // 重設文字內容  }  };  b1.addActionListener(a1);  //Step 3: 將元件加入面版  c.add(b1);  c.add(l1);  }