![]() |
![]() Fall Semester 2005 |
The assignment for today's lab will have two stages:
Here's the completed application, so you can test-drive it:Stage One. A college bookstore receives cartons of textbooks. In each shipment, each carton contains the same number of textbooks. The inventory manager wants to use a computer to calculate the total number of textbooks arriving at the bookstore for each shipment. The inventory manager will enter the number of cartons received and the fixed number of textbooks in each carton of the shipment; the application should then calculate and display the total number of textbooks in the shipment.
labTwo01.jar
Remember, you have to develop it from scratch, the code provided is meant to clarify the requirements.
Download the contents of the link to your desktop, then run the program as follows from the command line:
java -classpath labTwo01.jar Inventory
Here's the way the application will look when you run it:
Once this part is working we move on to the second set of requirements:
Here's the updated application, so you can test-drive it:Stage Two. The inventory manager notices a flaw in your Inventory application. Although the application calculates the correct result, that result continues to display even after new data is entered. The only time the output changes is when the Inventory manager clicks the Calculate
JButton
again. You should alter the Inventory application to clear the result as soon as the user enters new information into either of theJTextField
s, to avoid any confusion over the accuracy of your calculated result.
labTwo02.jar
Download the contents of the link to your desktop, then run the program as follows from the command line:
java -classpath labTwo02.jar Inventory
Your task is to provide an implementation that works exactly as the one you're test driving. This should represent the initial planning stage for the application:
Here's the answer to the minute paper of yesterday:
import javax.swing.*; import java.awt.*; import java.awt.event.*; class Three { public static void main(String[] args) { JFrame frame = new JFrame(); Container c = frame.getContentPane(); c.setBackground(new Color(0.66f, 1.0f, 0.66f)); c.setLayout(null); JTextField t = new JTextField(); t.setBounds(10, 120, 70, 20); c.add(t); KeyBroker k = new KeyBroker(); t.addKeyListener(k); JButton u = new JButton(); u.setBounds(100, 20, 90, 30); u.setText("Erase"); c.add(u); ButtonBroker b = new ButtonBroker(t); u.addActionListener(b); frame.setSize(300, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } class KeyBroker implements KeyListener { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { System.out.println("Ouch!"); } } class ButtonBroker implements ActionListener { JTextField t; ButtonBroker(JTextField t) { this.t = t; } public void actionPerformed(ActionEvent e) { System.out.println("Ha, ha!"); t.setText(""); } }