어서와 Java는 처음이지! 제13장 실전프로젝트.

Slides:



Advertisements
Similar presentations
Drawing in a frame – Java GUI
Advertisements

Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
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.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
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.
© 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’s and eventhandlers in java Martin Jagersand.
Graphical User Interfaces
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
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.
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.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington User Interface COMP 112 #30.
Combo Box, Check Boxes, and Radio Buttons. Radio Buttons User can click radio buttons, just like other buttons BUT Radio buttons are mutually exclusive.
Consolidation. Code making (i.e. making ciphers) is undertaken by a cryptographer whereas cryptanalysts try to break ciphers in order to gain intelligence.
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.
Chapter 12- GUI’s, Java, and Swing.. Overview n What are GUI’s n How Java does GUI’s- Swing n Buttons n Containers n Text I/O and Swing n Review.
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.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
1 Why layout managers Can we perform layout without them? –Yes. A container’s layout property can be set to null. Absolute positioning: specify size and.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
Event Handling Mohanraj S AP / IT Angel College of Engg & Tech.,
More GUI CSCE 190 – Java Instructor: Joel Gompert Lecture 8 – July 28, 2004.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
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.
Computer Science 209 GUIs Model/View/Controller Layouts.
Ch15 簡單計算機 物件導向系統實務. Ch22_Main.java import javax.swing.*; import java.awt.*; import java.awt.event.*; class Ch22_Main { public static void main(String.
GUI Tutorial 1. A Bit of Philosophy on what to Teach  There are numerous libraries, frameworks, options  Modern GUIs are often developed using XML (e.g.,
A: A: double “4” A: “34” 4.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
Graphical User Interface (GUI)
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.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
제 14 장 고급 스윙 컴포넌트.
Dept. of CSIE, National University of Tainan 10/21/2012 Working with Swing.
Import javax.swing.JOptionPane; public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; String lengthStr,
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 Programming in Java Hao Jiang Boston College April, 2009.
회원가입 - GUI ** 오지*.
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
Modular Event Handling
CSC 222: Computer Programming II
Java Applet What is a Java Applet? How is applet compiled?
Graphical User Interfaces -- GUIs
Swing JComponents.
GUIs Model/View/Controller Layouts
Java GUI.
CHAPTER 7 & 8 REVIEW QUESTIONS
Graphical User Interface (pronounced "gooey")
MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->
Review Operation Bingo
null, true, and false are also reserved.
PC02 Consolidation %WITTY_QUOTE%. PC02 Consolidation %WITTY_QUOTE%
class PrintOnetoTen { public static void main(String args[]) {
Steps to Creating a GUI Interface
Computer Science 209 Images and GUIs.
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

어서와 Java는 처음이지! 제13장 실전프로젝트

LAB: 계산기 작성 9장의 계산기에 이벤트 처리를 붙여서 완전한 계산기가 되도록 하여 보자.

SOLUTION public class Calculator extends JFrame implements ActionListener { private JPanel panel; private JTextField display; private JButton[] buttons; private String[] labels = { "Backspace", "", "", "CE", "C", "7", "8", "9", "/", "sqrt", "4", "5", "6", "x", "%", "1", "2", "3", "-", "1/x", "0", "-/+", ".", "+", "=", }; private double result = 0; private String operator = "="; private boolean startOfNumber = true; public Calculator() { display = new JTextField(35); panel = new JPanel(); display.setText("0.0"); //display.setEnabled(true);

SOLUTION panel.setLayout(new GridLayout(0, 5, 3, 3)); buttons = new JButton[25]; int index = 0; for (int rows = 0; rows < 5; rows++) { for (int cols = 0; cols < 5; cols++) { buttons[index] = new JButton(labels[index]); if (cols >= 3) buttons[index].setForeground(Color.red); else buttons[index].setForeground(Color.blue); buttons[index].setBackground(Color.yellow); panel.add(buttons[index]); buttons[index].addActionListener(this); index++; } add(display, BorderLayout.NORTH); add(panel, BorderLayout.CENTER); setVisible(true); pack();

SOLUTION public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.charAt(0) == 'C') { startOfNumber = true; result = 0; operator = "="; display.setText("0.0"); } else if (command.charAt(0) >= '0' && command.charAt(0) <= '9' || command.equals(".")) { if (startOfNumber == true) display.setText(command); else display.setText(display.getText() + command); startOfNumber = false; } else { if (startOfNumber) { if (command.equals("-")) { } else operator = command; double x = Double.parseDouble(display.getText()); calculate(x); }

SOLUTION private void calculate(double n) { if (operator.equals("+")) result += n; else if (operator.equals("-")) result -= n; else if (operator.equals("*")) result *= n; else if (operator.equals("/")) result /= n; else if (operator.equals("=")) result = n; display.setText("" + result); } public static void main(String args[]) { Calculator s = new Calculator();

Q & A