473,839 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GUI will not display

1 New Member
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 1690

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

Similar topics

9
2161
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 and frankly revolting. It is as though the software "engineers" have been thrown out and replaced with "programmers". That is to say, it is a sophomoric hack job, a hideous kludge.
15
6590
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 the buttons. The problem is when I post a form to itself, the Enter key will not submit the form, it only clears the contents of the text box. The only way I can submit is to click the submit button. Here is a simplified version of my code that I...
5
1516
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 to the eye (at least to my eye it's more appealing :^) To my mind this is very much what CSS is all about: allowing content providers to present properly coded data in a way they and, ideally, their readers, find inviting and accessible....
11
1977
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 agents to provide an improved experience than HTML with table layout. Notwithstanding the leadership of Chevrolet, Amnesty International and others, at what point do you think XHTML/CSS will become the preferred approach? Will it be when the number...
5
2309
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 (it's automatically generated). 1 user may finish 10, 20, or 50 jobs a day, but there can be at least 20-50 users per day, and they're always going to be different. The users aren't going to return, or if they do, it's always going to be under...
9
1498
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
1817
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 am still a novice, I am afraid. You can see the sample nav bar at www.tangerine-sky.com/horizontal_nav.html (I am pasting source code below) It's very simple, has the css included in the page ... works fine on a mac, okay on firefox on a PC but...
1
1458
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. The sql statement is a monster, I'll give you a taste down below. Code Set 1 : always displays fine do while not rsdata.eof response.write rsdata("NoteField")
5
2551
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 fails.... Any ideas??? <html> <head><title>New Details</title> </head> <center> <H2><IMG SRC="$(path)smlogo.gif"><br>
2
2610
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 button will display more and more records if it is availbale in data base. I am attachcing the screen shoot of my problem CMP is a column in the this record.
0
9698
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10592
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10656
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10299
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9434
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7022
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5684
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4067
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.