A Simple Text Editor Application
|
|
- Grant Hood
- 5 years ago
- Views:
Transcription
1 CASE STUDY 7 A Simple Text Editor Application To demonstrate the JTextArea component, fonts, menus, and file choosers we present a simple text editor application. This application allows you to create new text files and open existing text files. The file contents are displayed in a text area. You can also change the font and style of the text that is displayed in the text area. The application s window is shown in Figure CS7-1. Line wrapping is turned on, using word wrap style, and the text area is in a scroll pane. Figure CS7-1 The text editor window The application uses a menu system to perform these operations, which is shown in Figure CS7-2. Each menu item generates an action event that is handled by an action listener. The following section presents a summary of the actions performed by each menu item. CS7-1
2 CS7-2 Case Study 7 A Simple Text Editor Application Figure CS7-2 Menu system for the text editor application File Menu New Open Save This menu item clears any text that is stored in the text area. In addition, the class s filename field is set to null. The filename field contains the path and name of the file that is currently displayed in the text area. This menu item displays a file chooser that allows the user to select a file to open. If the user selects a file, it is opened and its contents are read into the text area. The path and name of the file are stored in the filename field. This menu item saves the contents of the text area. The contents are saved to the file with the name and path stored in the filename field. If the filename field is set to null, which would indicate that the file has not been saved yet, then this menu item performs the same action as the Save As menu item. Save As This menu item displays a file chooser that allows the user to select a location and file name. The contents of the text area are written to the selected file, and the path and file name are stored in the filename field. (Be careful when using this menu item. As it is currently written, this application does not warn you when you are about to overwrite an existing file!) Exit This menu item ends the application. Font Menu Monospaced Serif SansSerif Italic Bold This radio button menu item changes the text area s font to Monospaced. This radio button menu item changes the text area s font to Serif. This radio button menu item changes the text area s font to SansSerif. This check box menu item changes the text area s style to italic. This check box menu item changes the text area s style to bold. Code Listing CS7-1 shows the code for the TextEditor class. The main method creates an instance of the class, which displays the text editor window. Figure CS7-3 shows the window displaying text in various fonts and styles.
3 Case Study 7 A Simple Text Editor Application CS7-3 Figure CS7-3 Text displayed in various fonts and styles Code Listing CS7-1 (TextEditor.java) 1 import java.awt.*; 2 import java.awt.event.*; 3 import javax.swing.*; 4 import java.io.*; 5 6 /** 7 The TextEditor class is a simple text editor. 8 */ 9 10 public class TextEditor extends JFrame 11 { 12 // The following are fields for the menu system. 13 // First, the menu bar 14 private JMenuBar menubar; 15
4 CS7-4 Case Study 7 A Simple Text Editor Application 16 // The menus 17 private JMenu filemenu; 18 private JMenu fontmenu; // The menu items 21 private JMenuItem newitem; 22 private JMenuItem openitem; 23 private JMenuItem saveitem; 24 private JMenuItem saveasitem; 25 private JMenuItem exititem; // The radio button menu items 28 private JRadioButtonMenuItem monoitem; 29 private JRadioButtonMenuItem serifitem; 30 private JRadioButtonMenuItem sansserifitem; // The checkbox menu items 33 private JCheckBoxMenuItem italicitem; 34 private JCheckBoxMenuItem bolditem; private String filename; // To hold the file name 37 private JTextArea editortext; // To display the text 38 private final int NUM_LINES = 20; // Lines to display 39 private final int NUM_CHARS = 40; // Chars per line /** 42 Constructor 43 */ public TextEditor() 46 { 47 // Set the title. 48 settitle("text Editor"); // Specify what happens when the close 51 // button is clicked. 52 setdefaultcloseoperation(jframe.exit_on_close); // Create the text area. 55 editortext = new JTextArea(NUM_LINES, NUM_CHARS); // Turn line wrapping on. 58 editortext.setlinewrap(true); 59 editortext.setwrapstyleword(true); // Create a scroll pane and add the text area to it. 62 JScrollPane scrollpane = new JScrollPane(editorText); 63
5 Case Study 7 A Simple Text Editor Application CS // Add the scroll pane to the content pane. 65 add(scrollpane); // Build the menu bar. 68 buildmenubar(); // Pack and display the window. 71 pack(); 72 setvisible(true); 73 } /** 76 The buildmenubar method creates a menu bar and 77 calls the createfilemenu method to create the 78 file menu. 79 */ private void buildmenubar() 82 { 83 // Build the file and font menus. 84 buildfilemenu(); 85 buildfontmenu(); // Create the menu bar. 88 menubar = new JMenuBar(); // Add the file and font menus to the menu bar. 91 menubar.add(filemenu); 92 menubar.add(fontmenu); // Set the menu bar for this frame. 95 setjmenubar(menubar); 96 } /** 99 The buildfilemenu method creates the file menu 100 and populates it with its menu items. 101 */ private void buildfilemenu() 104 { 105 // Create the New menu item. 106 newitem = new JMenuItem("New"); 107 newitem.setmnemonic(keyevent.vk_n); 108 newitem.addactionlistener(new NewListener()); // Create the Open menu item. 111 openitem = new JMenuItem( Open );
6 CS7-6 Case Study 7 A Simple Text Editor Application 112 openitem.setmnemonic(keyevent.vk_o); 113 openitem.addactionlistener(new OpenListener()); // Create the Save menu item. 116 saveitem = new JMenuItem("Save"); 117 saveitem.setmnemonic(keyevent.vk_s); 118 saveitem.addactionlistener(new SaveListener()); // Create the Save As menu item. 121 saveasitem = new JMenuItem("Save As"); 122 saveasitem.setmnemonic(keyevent.vk_a); 123 saveasitem.addactionlistener(new SaveListener()); // Create the Exit menu item. 126 exititem = new JMenuItem("Exit"); 127 exititem.setmnemonic(keyevent.vk_x); 128 exititem.addactionlistener(new ExitListener()); // Create a menu for the items we just created. 131 filemenu = new JMenu("File"); 132 filemenu.setmnemonic(keyevent.vk_f); // Add the items and some separator bars to the menu. 135 filemenu.add(newitem); 136 filemenu.add(openitem); 137 filemenu.addseparator();// Separator bar 138 filemenu.add(saveitem); 139 filemenu.add(saveasitem); 140 filemenu.addseparator();// Separator bar 141 filemenu.add(exititem); 142 } /** 145 The buildfontmenu method creates the font menu 146 and populates it with its menu items. 147 */ private void buildfontmenu() 150 { 151 // Create the Monospaced menu item. 152 monoitem = new JRadioButtonMenuItem("Monospaced"); 153 monoitem.addactionlistener(new FontListener()); // Create the Serif menu item. 156 serifitem = new JRadioButtonMenuItem("Serif"); 157 serifitem.addactionlistener(new FontListener()); // Create the SansSerif menu item.
7 Case Study 7 A Simple Text Editor Application CS sansserifitem = 161 new JRadioButtonMenuItem("SansSerif", true); 162 sansserifitem.addactionlistener(new FontListener()); // Group the radio button menu items. 165 ButtonGroup group = new ButtonGroup(); 166 group.add(monoitem); 167 group.add(serifitem); 168 group.add(sansserifitem); // Create the Italic menu item. 171 italicitem = new JCheckBoxMenuItem("Italic"); 172 italicitem.addactionlistener(new FontListener()); // Create the Bold menu item. 175 bolditem = new JCheckBoxMenuItem("Bold"); 176 bolditem.addactionlistener(new FontListener()); // Create a menu for the items we just created. 179 fontmenu = new JMenu("Font"); 180 fontmenu.setmnemonic(keyevent.vk_t); // Add the items and some separator bars to the menu. 183 fontmenu.add(monoitem); 184 fontmenu.add(serifitem); 185 fontmenu.add(sansserifitem); 186 fontmenu.addseparator();// Separator bar 187 fontmenu.add(italicitem); 188 fontmenu.add(bolditem); 189 } /** 192 Private inner class that handles the event that 193 is generated when the user selects New from 194 the file menu. 195 */ private class NewListener implements ActionListener 198 { 199 public void actionperformed(actionevent e) 200 { 201 editortext.settext(""); 202 filename = null; 203 } 204 } /** 207 Private inner class that handles the event that
8 CS7-8 Case Study 7 A Simple Text Editor Application 208 is generated when the user selects Open from 209 the file menu. 210 */ private class OpenListener implements ActionListener 213 { 214 public void actionperformed(actionevent e) 215 { 216 int chooserstatus; JFileChooser chooser = new JFileChooser(); 219 chooserstatus = chooser.showopendialog(null); 220 if (chooserstatus == JFileChooser.APPROVE_OPTION) 221 { 222 // Get a reference to the selected file. 223 File selectedfile = chooser.getselectedfile(); // Get the path of the selected file. 226 filename = selectedfile.getpath(); // Open the file. 229 if (!openfile(filename)) 230 { 231 JOptionPane.showMessageDialog(null, 232 "Error reading " filename, "Error", 234 JOptionPane.ERROR_MESSAGE); 235 } 236 } 237 } /** 240 The openfile method opens the file specified by 241 filename and reads its contents into the text 242 area. The method returns true if the file was 243 opened and read successfully, or false if an 244 error occurred. filename The name of the file to open. 246 */ private boolean openfile(string filename) 249 { 250 boolean success; 251 String inputline, editorstring = ""; 252 FileReader freader; 253 BufferedReader inputfile; try
9 Case Study 7 A Simple Text Editor Application CS { 257 // Open the file. 258 freader = new FileReader(filename); 259 inputfile = new BufferedReader(freader); // Read the file contents into the editor. 262 inputline = inputfile.readline(); 263 while (inputline!= null) 264 { 265 editorstring = editorstring inputline + "\n"; 267 inputline = inputfile.readline(); 268 } 269 editortext.settext(editorstring); // Close the file. 272 inputfile.close(); // Indicate that everything went OK. 275 success = true; 276 } 277 catch (IOException e) 278 { 279 // Something went wrong. 280 success = false; 281 } // Return our status. 284 return success; 285 } 286 } /** 289 Private inner class that handles the event that 290 is generated when the user selects Save or Save 291 As from the file menu. 292 */ private class SaveListener implements ActionListener 295 { 296 public void actionperformed(actionevent e) 297 { 298 int chooserstatus; // If the user selected Save As, or the contents 301 // of the editor have not been saved, use a file 302 // chooser to get the file name. Otherwise, save 303 // the file under the current file name.
10 CS7-10 Case Study 7 A Simple Text Editor Application if (e.getactioncommand() == "Save As" 306 filename == null) 307 { 308 JFileChooser chooser = new JFileChooser(); 309 chooserstatus = chooser.showsavedialog(null); 310 if (chooserstatus == JFileChooser.APPROVE_OPTION) 311 { 312 // Get a reference to the selected file. 313 File selectedfile = 314 chooser.getselectedfile(); // Get the path of the selected file. 317 filename = selectedfile.getpath(); 318 } 319 } // Save the file. 322 if (!savefile(filename)) 323 { 324 JOptionPane.showMessageDialog(null, 325 "Error saving " filename, 327 "Error", 328 JOptionPane.ERROR_MESSAGE); 329 } 330 } /** 333 The savefile method saves the contents of the 334 text area to a file. The method returns true if 335 the file was saved successfully, or false if an 336 error occurred. filename The name of the file. true if successful, false otherwise. 339 */ private boolean savefile(string filename) 342 { 343 boolean success; 344 String editorstring; 345 FileWriter fwriter; 346 PrintWriter outputfile; try 349 { 350 // Open the file. 351 fwriter = new FileWriter(filename);
11 352 outputfile = new PrintWriter(fwriter); // Write the contents of the text area 355 // to the file. 356 editorstring = editortext.gettext(); 357 outputfile.print(editorstring); // Close the file. 360 outputfile.close(); // Indicate that everything went OK. 363 success = true; 364 } 365 catch (IOException e) 366 { 367 // Something went wrong. 368 success = false; 369 } // Return our status. 372 return success; 373 } 374 } /** 377 Private inner class that handles the event that 378 is generated when the user selects Exit from 379 the file menu. 380 */ private class ExitListener implements ActionListener 383 { 384 public void actionperformed(actionevent e) 385 { 386 System.exit(0); 387 } 388 } /** 391 Private inner class that handles the event that 392 is generated when the user selects an item from 393 the font menu. 394 */ private class FontListener implements ActionListener 397 { 398 public void actionperformed(actionevent e) 399 { Case Study 7 A Simple Text Editor Application CS7-11
12 CS7-12 Case Study 7 A Simple Text Editor Application 400 // Get the current font. 401 Font textfont = editortext.getfont(); // Retrieve the font name and size. 404 String fontname = textfont.getname(); 405 int fontsize = textfont.getsize(); // Start with plain style. 408 int fontstyle = Font.PLAIN; // Determine which font is selected. 411 if (monoitem.isselected()) 412 fontname = "Monospaced"; 413 else if (serifitem.isselected()) 414 fontname = "Serif"; 415 else if (sansserifitem.isselected()) 416 fontname = "SansSerif"; // Determine whether italic is selected. 419 if (italicitem.isselected()) 420 fontstyle += Font.ITALIC; // Determine whether bold is selected. 423 if (bolditem.isselected()) 424 fontstyle += Font.BOLD; // Set the font as selected. 427 editortext.setfont(new Font(fontName, 428 fontstyle, fontsize)); 429 } 430 } /** 433 main method 434 */ public static void main(string[] args) 437 { 438 TextEditor te = new TextEditor(); 439 } 440 }
Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus
Chapter 13 Lab Advanced GUI Applications Lab Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the user the option of when they will be seen.
More informationChapter 13 Lab Advanced GUI Applications
Gaddis_516907_Java 4/10/07 2:10 PM Page 113 Chapter 13 Lab Advanced GUI Applications Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the
More informationJava - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.
Java - Applications C&G Criteria: 5.3.2, 5.5.2, 5.5.3 Java applets require a web browser to run independently of the Java IDE. The Dos based console applications will run outside the IDE but have no access
More informationBuilding Graphical User Interfaces. Overview
Building Graphical User Interfaces 4.1 Overview Constructing GUIs Interface components GUI layout Event handling 2 1 GUI Principles Components: GUI building blocks. Buttons, menus, sliders, etc. Layout:
More informationBuilding Graphical User Interfaces. GUI Principles
Building Graphical User Interfaces 4.1 GUI Principles Components: GUI building blocks Buttons, menus, sliders, etc. Layout: arranging components to form a usable GUI Using layout managers. Events: reacting
More informationOverview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling
Overview Building Graphical User Interfaces Constructing GUIs Interface components GUI layout Event handling 4.1 GUI Principles AWT and Swing Components: GUI building blocks. Buttons, menus, sliders, etc.
More informationInheritance (cont) Abstract Classes
Inheritance (cont) Abstract Classes 1 Polymorphism inheritance allows you to define a base class that has fields and methods classes derived from the base class can use the public and protected base class
More informationJAVA NOTES GRAPHICAL USER INTERFACES
1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris July 2001 8 DROP-DOWN LISTS 8.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand and use JLists understand and use
More informationMore Swing. CS180 Recitation 12/(04,05)/08
More Swing CS180 Recitation 12/(04,05)/08 Announcements No lecture/labs next week Recitations and evening consulting hours will be held as usual. Debbie's study group on tuesday and office hours on thursday
More informationTheory Test 3A. University of Cape Town ~ Department of Computer Science. Computer Science 1016S ~ For Official Use
Please fill in your Student Number and, optionally, Name. For Official Use Student Number : Mark : Name : Marker : University of Cape Town ~ Department of Computer Science Computer Science 1016S ~ 2007
More informationPart 3: Graphical User Interface (GUI) & Java Applets
1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ
More informationAttempt FOUR questions Marking Scheme Time: 120 mins
Ahmadu Bello University Department of Computer Science Second Semester Examinations August 2017 COSC212: Object Oriented Programming II Marking Scheme Attempt FOUR questions Marking Scheme Time: 120 mins
More informationimport javax.swing.*; import java.awt.*; import java.awt.event.*;
I need to be walked through with why the stocks are being recognized "half way." They will print out in the console but won't be recognized by certain code. Every line of code seems to look right and that's
More informationChapter 12 GUI Basics
Chapter 12 GUI Basics 1 Creating GUI Objects // Create a button with text OK JButton jbtok = new JButton("OK"); // Create a label with text "Enter your name: " JLabel jlblname = new JLabel("Enter your
More informationDM550 / DM857 Introduction to Programming. Peter Schneider-Kamp
DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ GRAPHICAL USER INTERFACES 2 HelloWorld Reloaded
More informationQueens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide
Topics for Exam 2: Queens College, CUNY Department of Computer Science CS 212 Object-Oriented Programming in Java Practice Exam 2 CS 212 Exam 2 Study Guide Linked Lists define a list node define a singly-linked
More informationLösningsförslag till exempeldugga
till exempeldugga 1 (6) Kursnamn Objektorienterade applikationer Program DAI 2 Examinator Uno Holmer Modellering Designmönster a) Decorator. b) public class Singleton { private static Singleton instance
More informationII 12, JFileChooser. , 2. SolidEllipse ( 2), PolyLine.java ( 3). Draw.java
II 12, 13 (ono@isnagoya-uacjp) 2007 1 15, 17 2 : 1 2, JFileChooser, 2,,, Draw 1, SolidEllipse ( 2), PolyLinejava ( 3) 1 Drawjava 2 import javaxswing*; 3 import javaawtevent*; import javautil*; 5 import
More informationGUI Components Continued EECS 448
GUI Components Continued EECS 448 Lab Assignment In this lab you will create a simple text editor application in order to learn new GUI design concepts This text editor will be able to load and save text
More informationJAVA NOTES GRAPHICAL USER INTERFACES
1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris 24 June 2001 5 TEXT AREAS 5.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand how to get multi-line input from the
More informationHandout 14 Graphical User Interface (GUI) with Swing, Event Handling
Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement
More informationPART 23. Java GUI Advanced JList Component. more items.
PART 23 Java GUI Advanced 23.1 JList Component JList is a component that displays a list of objects. It allows the user to select one or more items. import java.awt.color; import java.awt.eventqueue; import
More informationJRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();
Q)Write a program to design an interface containing fields User ID, Password and Account type, and buttons login, cancel, edit by mixing border layout and flow layout. Add events handling to the button
More informationExample 3-1. Password Validation
Java Swing Controls 3-33 Example 3-1 Password Validation Start a new empty project in JCreator. Name the project PasswordProject. Add a blank Java file named Password. The idea of this project is to ask
More informationClass 16: The Swing Event Model
Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present
More informationSTREAMS. (fluxos) Objetivos
STREAMS (fluxos) Objetivos To be able to read and write files To become familiar with the concepts of text and binary files To be able to read and write objects using serialization To be able to process
More informationA sample print out is: is is -11 key entered was: w
Lab 9 Lesson 9-2: Exercise 1, 2 and 3: Note: when you run this you may need to maximize the window. The modified buttonhandler is: private static class ButtonListener implements ActionListener public void
More informationBased on slides by Prof. Burton Ma
Based on slides by Prof. Burton Ma 1 TV - on : boolean - channel : int - volume : int + power(boolean) : void + channel(int) : void + volume(int) : void Model View Controller RemoteControl + togglepower()
More informationJava Programming Lecture 6
Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components
More informationJLayeredPane. Depth Constants in JLayeredPane
JLayeredPane Continuing on Swing Components A layered pane is a Swing container that provides a third dimension for positioning components depth or Z order. The class for the layered pane is JLayeredPane.
More informationAdding Buttons to StyleOptions.java
Adding Buttons to StyleOptions.java The files StyleOptions.java and StyleOptionsPanel.java are from Listings 5.14 and 5.15 of the text (with a couple of slight changes an instance variable fontsize is
More information11/27/2007 TOPICS CHAPTER TOPICS LISTS READ ONLY TEXT FIELDS. Advanced GUI Applications. This module discusses the following main topics:
Advanced GUI Applications TOPICS This module discusses the following main topics: The Swing and AWT Class Hierarchy Read-Only Text Fields Lists Combo Boxes Displaying Images in Labels and Buttons Mnemonics
More information1 (6) Lösningsförslag Objektorienterade applikationer Provdatum Program DAI 2 Läsår 2016/2017, lp 3. Uppgift 1 (1+1+1 p) a)
till dugga P r e l i m i n ä r 1 (6) Kursnamn Objektorienterade applikationer Provdatum 2017-02-09 Program DAI 2 Läsår 2016/2017, lp 3 Examinator Uno Holmer Uppgift 1 (1+1+1 p) a) b) c) public interface
More informationCOURSE DESCRIPTION. John Lewis and William Loftus; Java: Software Solutions; Addison Wesley
COURSE DESCRIPTION Dept., Number Semester hours IS 323 Course Title 4 Course Coordinator Object Oriented Programming Catherine Dwyer and John Molluzzo Catalog Description (2004-2006) Continued development
More informationCSIS 10A Assignment 7 SOLUTIONS
CSIS 10A Assignment 7 SOLUTIONS Read: Chapter 7 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,
More information1.00 Lecture 14. Lecture Preview
1.00 Lecture 14 Introduction to the Swing Toolkit Lecture Preview Over the next 5 lectures, we will introduce you to the techniques necessary to build graphic user interfaces for your applications. Lecture
More informationGraphical User Interfaces 2
Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview
More informationTopic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"
More informationTopic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques
More information8/23/2014. Chapter Topics. Chapter Topics. Lists. Read Only Text Fields. Chapter 13: Advanced GUI Applications
Chapter 13: Advanced GUI Applications Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 13 discusses the following main topics: The Swing
More informationToday. cisc3120-fall2012-parsons-lectiii.3 2
MORE GUI COMPONENTS Today Last time we looked at some of the components that the: AWT Swing libraries provide for building GUIs in Java. This time we will look at several more GUI component topics. We
More information1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static
18 7 17 1 1.1 GUI ( ) GUI ( ) JFrame public class XXX extends JFrame { public XXX() { // XXX // init()... // ( )... init() main() public static public class XXX extends JFrame { public XXX() { // setsize(,
More informationMIT AITI Swing Event Model Lecture 17
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 user. But how do GUIs interact with users? How do applications
More informationJava Help Files. by Peter Lavin. May 22, 2004
Java Help Files by Peter Lavin May 22, 2004 Overview Help screens are a necessity for making any application user-friendly. This article will show how the JEditorPane and JFrame classes, along with HTML
More informationCSE143 - Project 3A Turn-in Receipt
1 of 9 11/24/2003 4:24 PM CSE143 - Project 3A Turn-in Receipt Prins, Ryan Michael (rprins@u.washington.edu) Section AD Daniel Wyatt Turn-in logged at 16:24:36 PST, Monday, Nov 24, 2003 Your program compiled
More informationLesson 3: Accepting User Input and Using Different Methods for Output
Lesson 3: Accepting User Input and Using Different Methods for Output Introduction So far, you have had an overview of the basics in Java. This document will discuss how to put some power in your program
More informationObject-Oriented Programming Design. Topic : User Interface Components with Swing GUI Part III
Electrical and Computer Engineering Object-Oriented Topic : User Interface Components with Swing GUI Part III Maj Joel Young Joel.Young@afit.edu 17-Sep-03 Maj Joel Young Creating GUI Apps The Process Overview
More informationClass 14: Introduction to the Swing Toolkit
Introduction to Computation and Problem Solving Class 14: Introduction to the Swing Toolkit Prof. Steven R. Lerman and Dr. V. Judson Harward 1 Class Preview Over the next 5 lectures, we will introduce
More information16-Dec-10. Consider the following method:
Boaz Kantor Introduction to Computer Science IDC Herzliya Exception is a class. Java comes with many, we can write our own. The Exception objects, along with some Java-specific structures, allow us to
More informationJava Project P6 Event Handling
Java Project P6 Event Handling NIM : 13122042 NAMA : Afrizal Hardiansyah Tampilan Menu Project P6 Coding Program Baris_Menu : import javax.swing.*; import java.awt.event.*; class Baris_Menu extends JFrame
More informationProject 1. Java Data types and input/output 1/17/2014. Primitive data types (2) Primitive data types in Java
Java Data types and input/output Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The University of Texas at Arlington, Arlington, TX 76019 Email:
More informationPractical Scala. Dianne Marsh Emerging Technology for the Enterprise Conference 03/26/2009
Practical Scala Dianne Marsh Emerging Technology for the Enterprise Conference dmarsh@srtsolutions.com 03/26/2009 Outline for Discussion Motivation and migration Demonstrate key implementation details
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void
More informationProgramming graphics
Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it
More informationLayouts and Components Exam
Layouts and Components Exam Name Period A. Vocabulary: Answer each question specifically, based on what was taught in class. Term Question Answer JScrollBar(a, b, c, d, e) Describe c. ChangeEvent What
More informationAP CS Unit 11: Graphics and Events
AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two
More informationRAIK 183H Examination 2 Solution. November 10, 2014
RAIK 183H Examination 2 Solution November 10, 2014 Name: NUID: This examination consists of 5 questions and you have 110 minutes to complete the test. Show all steps (including any computations/explanations)
More informationCSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7. Question 1. (2 points) What is the difference between a stream and a file?
CSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7 Question 1. (2 points) What is the difference between a stream and a file? A stream is an abstraction representing the flow of data from one place to
More informationFile Input and Output Recitation 04/03/2009. CS 180 Department of Computer Science, Purdue University
File Input and Output Recitation 04/03/2009 CS 180 Department of Computer Science, Purdue University Announcements Project 7 is out Fun project! With animation! Start early Exam grade has been released
More informationIntroduction to the JAVA UI classes Advanced HCI IAT351
Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing
More informationFrames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling
Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)
More informationWindow Interfaces Using Swing Objects
Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs
More informationI/O Framework and Case Study. CS151 Chris Pollett Nov. 2, 2005.
I/O Framework and Case Study CS151 Chris Pollett Nov. 2, 2005. Outline Character Streams Random Access Files Design case study Planning Iterations Character Streams Java internally represents strings as
More informationCSE 8B Intro to CS: Java
CSE 8B Intro to CS: Java Winter, 2006 February 23 (Day 14) Menus Swing Event Handling Inner classes Instructor: Neil Rhodes JMenuBar container for menus Menus associated with a JFrame via JFrame.setMenuBar
More informationPRÁCTICO 1: MODELOS ESTÁTICOS INGENIERÍA INVERSA DIAGRAMAS DE CLASES
PRÁCTICO 1: MODELOS ESTÁTICOS INGENIERÍA INVERSA DIAGRAMAS DE CLASES Una parte importante dentro del proceso de re-ingeniería de un sistema es la ingeniería inversa del mismo, es decir, la obtención de
More informationInput from Files. Buffered Reader
Input from Files Buffered Reader Input from files is always text. You can convert it to ints using Integer.parseInt() We use BufferedReaders to minimize the number of reads to the file. The Buffer reads
More information13 (ono@is.nagoya-u.ac.jp) 2008 1 15 1 factory., factory,. 2 2.,, JFileChooser. 1. Java,,, Serializable *1., FigBase ( 1). FigBase.java 3 5. 1 import java. lang.*; 2 import java. awt.*; 3 import java.
More informationGraphical User Interfaces 2
Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 2011 Extending JFrame Dialog boxes Overview Ge
More informationCSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More information11/1/2011. Chapter Goals
Chapter Goals To be able to read and write text files To learn how to throw exceptions To be able to design your own exception classes To understand the difference between checked and unchecked exceptions
More informationGPolygon GCompound HashMap
Five-Minute Review 1. How do we construct a GPolygon object? 2. How does GCompound support decomposition for graphical objects? 3. What does algorithmic complexity mean? 4. Which operations does a HashMap
More informationOutline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics
Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming
More informationCN208 Introduction to Computer Programming
CN208 Introduction to Computer Programming Lecture #11 Streams (Continued) Pimarn Apipattanamontre Email: pimarn@pimarn.com 1 The Object Class The Object class is the direct or indirect superclass of every
More informationDM503 Programming B. Peter Schneider-Kamp.
DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! GRAPHICAL USER INTERFACES 2 HelloWorld Reloaded Java standard GUI package is Swing from popup message
More informationGraphical User Interfaces 2
Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Ge?ng user input Overview Displaying message or error Listening for
More informationCOSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 123 Computer Creativity Graphics and Events Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Draw shapes, text in various fonts, and colors. 2) Build
More informationVariables of class Type. Week 8. Variables of class Type, Cont. A simple class:
Week 8 Variables of class Type - Correction! Libraries/Packages String Class, reviewed Screen Input/Output, reviewed File Input/Output Coding Style Guidelines A simple class: Variables of class Type public
More informationSorting/Searching and File I/O
Sorting/Searching and File I/O Sorting Searching CLI: File Input CLI: File Output GUI: File Chooser Reading for this lecture: 13.1 (and other sections of Chapter 13) 1 Sorting Sorting is the process of
More informationStating Your Preferences
Stating Your Preferences James W. Cooper Sometimes you don t remember what you prefer. For example, when you dine at the famous French restaurant Picholine, and are confronted with their mammoth cheese
More informationChapter 13 GUI Basics. Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved.
Chapter 13 GUI Basics 1 Motivations The design of the API for Java GUI programming is an excellent example of how the object-oriented principle is applied. In the chapters that follow, you will learn the
More informationApéndice A. Código fuente de aplicación desarrollada para probar. implementación de IPv6
Apéndice A Código fuente de aplicación desarrollada para probar implementación de IPv6 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.net.*; import java.util.enumeration;
More informationBasics of programming 3. Java GUI and SWING
Basics of programming 3 Java GUI and SWING Complex widgets Basics of programming 3 BME IIT, Goldschmidt Balázs 2 Complex widgets JList elements can be selected from a list JComboBox drop down list with
More informationLösningsförslag till tentamen
till tentamen 1 (5) Kursnamn Objektorienterade applikationer Tentamensdatum 2018-08-27 Program DAI 2 Läsår 2017/2018, lp 3 Examinator Uno Holmer Uppgift 1 (6 p) Detta diagram är ett exempel på designmönstret
More informationLab 5: Java IO 12:00 PM, Feb 21, 2018
CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lab 5: Java IO 12:00 PM, Feb 21, 2018 1 The Java IO Library 1 2 Program Arguments 2 3 Readers, Writers, and Buffers 2 3.1 Buffering
More informationSwing Programming Example Number 2
1 Swing Programming Example Number 2 Problem Statement (Part 1 and 2 (H/w- assignment) 2 Demonstrate the use of swing Label, TextField, RadioButton, CheckBox, Listbox,Combo Box, Toggle button,image Icon
More informationIntroduction This assignment will ask that you write a simple graphical user interface (GUI).
Computing and Information Systems/Creative Computing University of London International Programmes 2910220: Graphical Object-Oriented and Internet programming in Java Coursework one 2011-12 Introduction
More informationImplementing Graphical User Interfaces
Chapter 6 Implementing Graphical User Interfaces 6.1 Introduction To see aggregation and inheritance in action, we implement a graphical user interface (GUI for short). This chapter is not about GUIs,
More informationComputer Science II - Test 1
Computer Science II - Test 1 Question 1. (15 points) a) For each of the access modifier keywords, what does each of them signify? public - private - protected - b) For each of the following programming
More informationWindow Interfaces Using Swing Objects
Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs
More informationenum: Enumerated Type An "enum" is a type with a fixed set of elements.
enum: Enumerated Type An "enum" is a type with a fixed set of elements. What is "enum" "enum" (enumeration) defines a new data type that has a fixed set of values. Example: an enum named Size with 3 fixed
More informationJava - Applets. public class Buttons extends Applet implements ActionListener
Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;
More informationSwing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff
Swing UI by Vlad Costel Ungureanu for Learn Stuff User Interface Command Line Graphical User Interface (GUI) Tactile User Interface (TUI) Multimedia (voice) Intelligent (gesture recognition) 2 Making the
More informationFunctors - Objects That Act Like Functions
Steven Zeil October 25, 2013 Contents 1 Functors in Java 2 1.1 Functors............. 2 1.2 Immediate Classes....... 6 2 Functors and GUIs 8 2.1 Java Event Listeners....... 10 3 Functors in C++ 22 3.1 operator()............
More informationGoals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords
Goals By the end of this lesson, you should: Lecture 7 More GUI programming 1. Be able to write Java s with JTextField, JList, JCheckBox and JRadioButton components 2. Be able to implement a ButtonGroup
More informationIT101. File Input and Output
IT101 File Input and Output IO Streams A stream is a communication channel that a program has with the outside world. It is used to transfer data items in succession. An Input/Output (I/O) Stream represents
More informationIntroduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008
Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Announcements A3 is up, due Friday, Oct 10 Prelim 1 scheduled for Oct 16 if you have a conflict, let us know now 2 Interactive
More informationChapter 4: Loops and Files
Chapter 4: Loops and Files Chapter Topics Chapter 4 discusses the following main topics: The Increment and Decrement Operators The while Loop Using the while Loop for Input Validation The do-while Loop
More informationCS193k, Stanford Handout #16
CS193k, Stanford Handout #16 Spring, 99-00 Nick Parlante Practice Final Final Exam Info Our regular exam time is Sat June 3rd in Skilling Aud (our regular room) from 3:30-5:30. The alternate will be Fri
More informationQuestion 1. (2 points) What is the difference between a stream and a file?
CSE 143 Sp03 Midterm 2 Page 1 of 7 Question 1. (2 points) What is the difference between a stream and a file? Question 2. (2 points) Suppose we are writing an online dictionary application. Given a word
More informationEvents and Exceptions
Events and Exceptions Analysis and Design of Embedded Systems and OO* Object-oriented programming Jan Bendtsen Automation and Control Lecture Outline Exceptions Throwing and catching Exceptions creating
More information