Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Simulate a Checkout Line at a Supermarket - Project 2 | CS 402, Study Guides, Projects, Research of Computer Science

Material Type: Project; Class: Introduction to Advanced Studies II; Subject: Computer Science; University: Illinois Institute of Technology; Term: Spring 2002;

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/18/2009

koofers-user-hoq
koofers-user-hoq 🇺🇸

10 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CS402
Java Handout for Project #2
Simulate a Checkout Line at a
Supermarket
Implementation Help
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Simulate a Checkout Line at a Supermarket - Project 2 | CS 402 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CS

Java Handout for Project

Simulate a Checkout Line at a

Supermarket

Implementation Help

Project2: Simulate a checkout

line at a supermarket (JApplet)

  • Note:
    • ChkOutApplet.bat

appletviewer -J-Djava.security.policy=ChkOutApplet.policy ChkOutApplet.html

  • ChkOutApplet.policy

grant {

permission java.security.AllPermission;

  • ChkOutApplet.html

JFileChooser: showSaveDialog

and showOpenDialog method

  • javax.swing.JFileChooser extends JComponent implements Accessible
  • int showSaveDialog(Component parent)
    • Pops up a "Save File" file chooser dialog.
    • Return: JFileChooser.CANCEL_OPTION, JFileChooser.APPROVE_OPTION and JFileCHooser.ERROR_OPTION
  • int showOpenDialog(Component parent)
    • Pops up an "Open File" file chooser dialog.
  • Ex.

JFileChooser fileSelect = new JFileChooser();

int option = fileSelect.showSaveDialog (this); // showOpenDialog(this);

if (option == JFileChooser.APPROVE_OPTION) {

// statements

JFileChooser: getSelectedFile

method

  • javax.swing.JFileChooser

extends JComponent

implements Accessible

  • File getSelectedFile()
    • Returns the selected file.
  • Ex.

JFileChooser fileSelect = new JFileChooser(); File fileName = fileselect.getSelectedFile ();

JComboBox: getSelectedIndex

method

  • javax.swing.JComboBox

public class JComboBox extends JComponent

  • int getSelectedIndex()
    • Returns the first item in the list that matches the given item.
  • Ex.

simulate (customerArrivalRate.getSelectedIndex()+3, customerArrivalRate.getSelectedIndex()+3); int next_arrival = (int)(Math.random () * selectArrival + 1);

FileWriter and FileReader

  • java.io.FileWriter

public class FileWriter

extends OutputStreamWriter

  • Convenience class for writing character files.
  • java.io.FileReader

public class FileReader

extends InputStreamReader

  • Convenience class for reading character files.

BufferedReader: readLine

method

  • java.io.BufferedReader public class BufferedReader extends Reader
    • Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
  • String readLine()
    • Read a line of text.
  • Ex. BufferedReader br = new BufferedReader(new FileReader(fileName)); outputArea.setText(""); String line; while ( (line = br.readLine() )!= null ) { outputArea.append(line); outputArea.append("\n"); } // display data in GUI br.close();

Simulate a Checkout Line at a

Supermarket

ComboBox