Ch15 簡單計算機 物件導向系統實務. Ch22_Main.java import javax.swing.*; import java.awt.*; import java.awt.event.*; class Ch22_Main { public static void main(String.

Slides:



Advertisements
Similar presentations
Drawing in a frame – Java GUI
Advertisements

JAVA 程式語言入門 (II).  版面配置  事件驅動  Ch14_01.java 1. import javax.swing.*; 2. import java.awt.*; 3. class Ch14_01 4. { 5. public static void main(String.
PayCalculator. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class PayCalculator extends JFrame implements ActionListener.
What is Covered Everything up to and including Lecture 11 Types Recursion (including grammars) Lists and Trees GUIs Does not include Big-O notation (Lecture.
GUI Tutorial Day 3. Custom Dialog Create, display, hide, retrieve information.
CPSC 233 Tutorial #17. GUI programming Objective – To understand better how to create simple interactive GUI programs.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
© L.Lúcio, An example GUI in Java n Two graphic libraries in Java u AWT u Swing n Swing is more recent than AWT: u Built on top of AWT classes;
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.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Lecture 19 Graphics User Interfaces (GUIs)
Final Review. Review A Binary Search divides a sorted data structure into two equal parts and each time throws away the part that cannot contain the item.
Graphical User Interfaces
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
Introduction to GUI Java offers a great number of pre-defined classes to support the development of graphical user interfaces –These are broken down into.
Button 元件. public class ko12_1 extends Applet implements ActionListener { Label lb=new Label(" 輸入密碼 :"); TextField tf1=new TextField(25); Button bn=new.
Consolidation. Code making (i.e. making ciphers) is undertaken by a cryptographer whereas cryptanalysts try to break ciphers in order to gain intelligence.
F27SB2 Software Development 2 Lecture 6: Java GUIs 5.
Layout Management Containers can arrange their components. Our container is a JPanel, and it can set the way it’s components will be laid out : mypanel.setLayout.
Lesson 36: The calculator – Java Applets. 1. Creating Your First Applet HelloWorldApp is an example of a Java application, a standalone program. Now you.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
CS Lecture 01 Frames and Components and events Lynda Thomas
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
SWING. AbstractButton Swing Buttons are subclasses of the AbstractButton class, which extends JComponent. Abstract class javax.swing.AbstractButton AbstractButton.
More GUI CSCE 190 – Java Instructor: Joel Gompert Lecture 8 – July 28, 2004.
Object-Oriented Programming (Java), Unit 18 Kirk Scott 1.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Event Driven Programming. Event-driven Programming In the early days of computing communication with the outside world was accomplished using a technique.
1 Class 6. 2 Objectives Objectives Enable your applications to perform actions in response to JButton clicks Get the text the user enters in a textfield.
Class Class 20 Objectives Use JCheckbox, JRadioButton, and a JComboBox in a UID.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
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];
Topic 13 List Boxes. JList Generates an ListSelectionEvent Event monitored by ListSelectionListener ListSelectionListener invokes method valueChanged.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7-2 ( Book Chapter 14) GUI and Event-Driven Programming.
Computer Science 209 GUIs Model/View/Controller Layouts.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 4 – Completing the Inventory Application.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation..
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
import java.io.*; public class Customer implements Serializable { public Customer(int theAge, int theSex, String[] theHobbies) { age = theAge; sex.
제 14 장 고급 스윙 컴포넌트.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
회원가입 - GUI ** 오지*.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Lecture 6 Object Oriented Programming Using Java By Rashid Ahmad Department of Computer Science University of Peshawar.
Design Applet based java program to find the area and perimeter of a rectangle given its length and width. Java GUI.
Multiple buttons and action calls
Lecture 11 Object Oriented Programming Using Java
Java Applet What is a Java Applet? How is applet compiled?
Graphical User Interfaces -- GUIs
GUIs Model/View/Controller Layouts
MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->
Course Outcomes of Advanced Java Programming AJP (17625, C603)
class PrintOnetoTen { public static void main(String args[]) {
어서와 Java는 처음이지! 제13장 실전프로젝트.
Computer Science 209 Images and GUIs.
CiS 260: App Dev I Chapter 6: GUI and OOD.
Final Review.
Presentation transcript:

Ch15 簡單計算機 物件導向系統實務

Ch22_Main.java import javax.swing.*; import java.awt.*; import java.awt.event.*; class Ch22_Main { public static void main(String [] args) { Ch22_Win_09 w = new Ch22_Win_09(); w.setSize(300, 250); w.setVisible(true); w.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }

Ch22_Win_09.java import javax.swing.*; import java.awt.*; import java.awt.event.*; class Ch22_Win_09 extends JFrame implements ActionListener { Container c = getContentPane(); GridLayout gl = new GridLayout(2,1); JPanel up_panel = new JPanel(); JPanel down_panel = new JPanel(); JLabel l1 = new JLabel(" 結果 "); JTextField tf1 = new JTextField(15); JButton [] b = new JButton[10]; JButton badd = new JButton("+"); JButton bequal = new JButton("="); static boolean clear = true; static int result = 0; Ch22_Win_09() { super(" 計算機 "); c.setBackground(Color.green); c.setLayout(gl); up_panel.setBackground(Color.red); down_panel.setBackground(Color.yellow); up_panel.add(l1); up_panel.add(tf1); for(int i = 0; i < 10; i++) { b[i] = new JButton(""+i); b[i].addActionListener(this); down_panel.add(b[i]); } badd.addActionListener(this); bequal.addActionListener(this); down_panel.add(badd); down_panel.add(bequal); c.add(up_panel); c.add(down_panel); } public void actionPerformed(ActionEvent e) { String temp_tf1; for(int i = 0; i < 10; i++) { if(e.getSource() == b[i]) { if(clear) tf1.setText("" + i); else tf1.setText(tf1.getText() + i); clear = false; } if(e.getSource() == badd) { clear = true; result = result + Integer.parseInt(tf1.getText()); tf1.setText("" + result); } if(e.getSource() == bequal) { clear = true; result = result + Integer.parseInt(tf1.getText()); tf1.setText("" + result); }