My code compiles and runs but the GUI will not display. I have tinkered with it but cannot get it to come up. Someone said I may be miscalling my GUI in this code, help?
Thank you. - import javax.swing.*;
-
-
import java.awt.event.*;
-
-
public class Application_MainRunInv extends JFrame {
-
-
private JTextArea txt;
-
private Inventory inv;
-
private int currentDisplay = 0;
-
-
public Application_MainRunInv() {
-
super("Pencil Warehouse");
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Prompts program to quit when closed
-
}
-
-
public void init() {
-
//Creates 3 Pencil Types
-
Brand p1 = new Brand(120, "Charcoal Pencil", 41, 1.97, "Stanford");
-
Brand p2 = new Brand(121, "Colored", 82, 1.49, "Stanford");
-
Brand p3 = new Brand(123, "Number2", 53, .97, "Woodward");
-
-
//Creates an inventory for the information
-
inv = new Inventory();
-
inv.add(p1);
-
inv.add(p2);
-
inv.add(p3);
-
-
inv.sort();
-
-
//Outputs the above information
-
-
for (int i = 0; i < inv.size(); i++) {
-
System.out.println("Pencil Number: " + inv.get(i).getPencilNumber());
-
System.out.println("Pencil Name: " + inv.get(i).getPencilName());
-
System.out.println("Pencil Stock: " + inv.get(i).getPencilStock());
-
System.out.println("Pencil Cost: $" + String.format("%.2f",inv.get(i).getPencilCost()));
-
System.out.println("Total Inventory Value: $" + String.format("%.2f",inv.get(i).TotalValue()));
-
System.out.println("Restocking-Fee: $" + String.format("%.2f",inv.get(i).RestockingFee()));
-
}
-
-
-
System.out.println("Total Inventory Value: $" + String.format("%.2f",inv.TotalValue()));
-
-
//Sets up the interface prior to button creation
-
JPanel panel = new JPanel();
-
txt = new JTextArea(15,40);
-
txt.setEditable(false);
-
panel.add(txt);
-
-
JButton original = new JButton("Original");
-
original.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
currentDisplay = 0;
-
displayPencil();
-
}
-
});
-
panel.add(original);
-
JButton previous = new JButton("Previous");
-
previous.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
if (currentDisplay > 0) currentDisplay--;
-
else currentDisplay = inv.size()-1;
-
displayPencil();
-
}
-
});
-
panel.add(previous);
-
JButton next = new JButton("Next");
-
next.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
if (currentDisplay < inv.size()-1) currentDisplay++;
-
else currentDisplay = 0;
-
displayPencil();
-
}
-
});
-
panel.add(next);
-
JButton end = new JButton("End");
-
end.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
currentDisplay = inv.size()-1;
-
displayPencil();
-
}
-
});
-
-
panel.add(end);
-
panel.add(new Graphic());
-
-
getContentPane().add(panel);
-
-
displayPencil();
-
}
-
-
public void displayPencil() {
-
txt.setText("Pencil Information:\n");
-
txt.append("Pencil Number: " + inv.get(currentDisplay).getPencilNumber() + "\n");
-
txt.append("Pencil Name: " + inv.get(currentDisplay).getPencilName() + "\n");
-
txt.append("Pencil Stock: " + inv.get(currentDisplay).getPencilStock() + "\n");
-
txt.append("Pencil Cost: $" + String.format("%.2f",inv.get(currentDisplay).getPencilCost()) + "\n");
-
txt.append("Total Inventory Value: $" + String.format("%.2f",inv.get(currentDisplay).TotalValue()) + "\n");
-
txt.append("Restocking-Fee: $" + String.format("%.2f",inv.get(currentDisplay).RestockingFee()) + "\n\n");
-
txt.append("Total Inventory Value: $" + String.format("%.2f",inv.TotalValue()));
-
-
-
}
-
-
public static void main(String args[]) {
-
Application_MainRunInv gui = new Application_MainRunInv();
-
gui.pack();
-
gui.setVisible(true);
-
}
-
//
-
}
0 1671 Sign in to post your reply or Sign up for a free account.
Similar topics
by: flarkblark |
last post by:
I recently had the displeasure of looking at the code
required to implement the pop-up menus used in a pulldown
menu system for a webpage.
The sheer amount of Javascript required was amazing...
|
by: M Smith |
last post by:
I have a form I want to submit to itself. I want to be able to type in a
list of numbers and submit the form and have that list show up on the same
form under the text box I typed them into and...
|
by: aboycalled3 |
last post by:
I'm interested in using the fascinating CSS available at
http://www.moronicbajebus.com/playground/cssplay/reformat-table/
which allows one to present tabular data in a way that's more appealing...
|
by: Simon Shutter |
last post by:
Forgive me if I am posting to wrong newsgroup and for a couple of loaded
questions.
First, from what I understand, one of the advantages of XHTML/CSS is the
ability of screen readers/braille...
|
by: keith |
last post by:
This may seem simple, but I'm having a bit of trouble figuring out
exactly how to do it. I'm accessing a database through an ODBC link,
and I have a query that returns only jobs completed that day...
|
by: bhavik.patel |
last post by:
Hi
I have a rather simple question:
I have following class definitions:
class Base
{
public:
virtual void display ()
|
by: atombee |
last post by:
Hi- this is the project that will not end! (sure you've all been there). I had originally purchased a php/css nav bar for the client, but it was buggy as hell, so I decided to do in css, in which I...
|
by: sudermatt |
last post by:
This one is completely baffling.
DB Enviornment: MSSQL database
Code Environment: ASP / VBscript (obviously)
Problem: data from an nText field disappears from conn.execute(sql) recordset. ...
|
by: plumba |
last post by:
Hi all
I have a form (see below), which for some reason has decided to stop functioning all together. It just does not call up the function. It is called up in the opening <form> tag but...
|
by: sumanta123 |
last post by:
Dear Sir,
In my develpment i am getting stuck for a senario.Kindly please help me for it.
Everytime we give the request we get the response of 8 records and
its corresponding value.
Then next...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |