473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

GUI will not display

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.

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2.  
  3. import java.awt.event.*;
  4.  
  5. public class Application_MainRunInv extends JFrame {
  6.  
  7. private JTextArea txt;
  8. private Inventory inv;
  9. private int currentDisplay = 0;
  10.  
  11. public Application_MainRunInv() {
  12. super("Pencil Warehouse");
  13. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Prompts program to quit when closed
  14. }
  15.  
  16. public void init() {
  17. //Creates 3 Pencil Types
  18. Brand p1 = new Brand(120, "Charcoal Pencil", 41, 1.97, "Stanford");
  19. Brand p2 = new Brand(121, "Colored", 82, 1.49, "Stanford");
  20. Brand p3 = new Brand(123, "Number2", 53, .97, "Woodward");
  21.  
  22. //Creates an inventory for the information
  23. inv = new Inventory();
  24. inv.add(p1);
  25. inv.add(p2);
  26. inv.add(p3);
  27.  
  28. inv.sort();
  29.  
  30. //Outputs the above information
  31.  
  32. for (int i = 0; i < inv.size(); i++) {
  33. System.out.println("Pencil Number: " + inv.get(i).getPencilNumber());
  34. System.out.println("Pencil Name: " + inv.get(i).getPencilName());
  35. System.out.println("Pencil Stock: " + inv.get(i).getPencilStock());
  36. System.out.println("Pencil Cost: $" + String.format("%.2f",inv.get(i).getPencilCost()));
  37. System.out.println("Total Inventory Value: $" + String.format("%.2f",inv.get(i).TotalValue()));
  38. System.out.println("Restocking-Fee: $" + String.format("%.2f",inv.get(i).RestockingFee()));
  39. }
  40.  
  41.  
  42. System.out.println("Total Inventory Value: $" + String.format("%.2f",inv.TotalValue()));
  43.  
  44. //Sets up the interface prior to button creation
  45. JPanel panel = new JPanel();
  46. txt = new JTextArea(15,40);
  47. txt.setEditable(false);
  48. panel.add(txt);
  49.  
  50. JButton original = new JButton("Original");
  51. original.addActionListener(new ActionListener() {
  52. public void actionPerformed(ActionEvent e) {
  53. currentDisplay = 0;
  54. displayPencil();
  55. }
  56. });
  57. panel.add(original);
  58. JButton previous = new JButton("Previous");
  59. previous.addActionListener(new ActionListener() {
  60. public void actionPerformed(ActionEvent e) {
  61. if (currentDisplay > 0) currentDisplay--;
  62. else currentDisplay = inv.size()-1;
  63. displayPencil();
  64. }
  65. });
  66. panel.add(previous);
  67. JButton next = new JButton("Next");
  68. next.addActionListener(new ActionListener() {
  69. public void actionPerformed(ActionEvent e) {
  70. if (currentDisplay < inv.size()-1) currentDisplay++;
  71. else currentDisplay = 0;
  72. displayPencil();
  73. }
  74. });
  75. panel.add(next);
  76. JButton end = new JButton("End");
  77. end.addActionListener(new ActionListener() {
  78. public void actionPerformed(ActionEvent e) {
  79. currentDisplay = inv.size()-1;
  80. displayPencil();
  81. }
  82. });
  83.  
  84. panel.add(end);
  85. panel.add(new Graphic());
  86.  
  87. getContentPane().add(panel);
  88.  
  89. displayPencil();
  90. }
  91.  
  92. public void displayPencil() {
  93. txt.setText("Pencil Information:\n");
  94. txt.append("Pencil Number: " + inv.get(currentDisplay).getPencilNumber() + "\n");
  95. txt.append("Pencil Name: " + inv.get(currentDisplay).getPencilName() + "\n");
  96. txt.append("Pencil Stock: " + inv.get(currentDisplay).getPencilStock() + "\n");
  97. txt.append("Pencil Cost: $" + String.format("%.2f",inv.get(currentDisplay).getPencilCost()) + "\n");
  98. txt.append("Total Inventory Value: $" + String.format("%.2f",inv.get(currentDisplay).TotalValue()) + "\n");
  99. txt.append("Restocking-Fee: $" + String.format("%.2f",inv.get(currentDisplay).RestockingFee()) + "\n\n");
  100. txt.append("Total Inventory Value: $" + String.format("%.2f",inv.TotalValue()));
  101.  
  102.  
  103. }
  104.  
  105. public static void main(String args[]) {
  106. Application_MainRunInv gui = new Application_MainRunInv();
  107. gui.pack();
  108. gui.setVisible(true);
  109. }
  110. //
  111. }
Jan 12 '10 #1
0 1664

Sign in to post your reply or Sign up for a free account.

Similar topics

9
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...
15
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...
5
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...
11
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...
5
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...
9
by: bhavik.patel | last post by:
Hi I have a rather simple question: I have following class definitions: class Base { public: virtual void display ()
1
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...
1
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. ...
5
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.