473,805 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't figure out why nothing shows

7 New Member
I have this massively long(to me) code and I get so excited that it's finally finish so I go to compile it to only get 18 errors then after figuring out almost all the errors, I run the program and nothing shows...can anyone help??? I don't know whether I should post the entire code or not...
Dec 4 '08 #1
8 1999
chaarmann
785 Recognized Expert Contributor
maybe it's stuck in an endless loop. Or you skipped the output with an if-statement. Or you returned from your function too early.
Just use a debugger and trace it step by step to see what's going on.

If you don't have a debugger, insert many
Expand|Select|Wrap|Line Numbers
  1. System.out.println("breakpoint X")
.
between every 5 lines or so, choosing another number every time for "X".
Then run the program and see see which one was the last that was printed. This is the hot spot.
Posting the code would be very helpful, but if it's too long nobody would read it. Just post only the code snippet around the hot spot.
Dec 4 '08 #2
JosAH
11,448 Recognized Expert MVP
@Sarii

You fell for a beginners' trap: you kept on typing code for a long time, tried to compile the entire shebang, fixed all your typos and now you're stuck with some program that doesn't do what you want it to do.

Better take baby steps: design one or two small methods and test them in isolation. True, you have to write a bit of code for the tests but afterwards you can be pretty sure those few methods work. Then add some more methods and repeat the testing.

Maybe you have typed a bit more characters in total but you don't end up pulling your hair out in despair. Remember this.

kind regards,

Jos
Dec 4 '08 #3
Sarii
7 New Member
I just don't know what to do cause I write it by pieces and put it all together...and all my other programs are similar...I just don't know why nothing shows still...It's awfully long and deals with GUIs...multiple JPanels, blah blah blah...I'm just trying to learn how to use different layout types and it's just crashing on me. I suppose me posting the code wouldn't hurt.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.text.DecimalFormat;
  6. import java.util.*;
  7. import java.lang.*;
  8.  
  9. public class grid extends JPanel implements ActionListener
  10. {
  11.     JFrame controllingFrame;
  12.     JTextField atf,btf,ctf,dtf,etf,ftf,gtf,htf,itf,jtf,ktf,ltf,mtf,ntf,otf,ptf,qtf,rtf,stf,ttf;
  13.     JLabel w,la,lb,lc,ld,le,w1,w2,w3,w4;
  14.     Container contentPane;
  15.     static final int AREA = 5;
  16.     static final double RATE = 5.00;
  17.     static final double TAX = 0.20;
  18.     private static String CALC = "calculate";
  19.     private static String EXIT = "exit";
  20.     private static String nline= "\n";
  21.     DecimalFormat twoDigits = new DecimalFormat("0.00");
  22.  
  23.     public grid(JFrame f)
  24.     {
  25.         controllingFrame = f;
  26.         f.setLayout(new GridLayout(3,1));
  27.         //f.setVgap(5);
  28.  
  29.         JPanel labels = createLabels();
  30.         JPanel textgrid = createTextgrid();
  31.         JComponent buttons = createButtonPanel();
  32.  
  33.         add(labels);
  34.         add(textgrid);
  35.         add(buttons);
  36.     }
  37.     public JPanel createLabels()
  38.     {
  39.         JPanel l = new JPanel(new GridLayout(0,6));
  40.         //l.setVgap(3);
  41.  
  42.         w = new JLabel("Week");
  43.         la = new JLabel("Hours");
  44.         lb = new JLabel("Tips");
  45.         lc = new JLabel("Gross");
  46.         ld = new JLabel("Taxes");
  47.         le = new JLabel("Net Pay");
  48.  
  49.         l.add(w);
  50.         l.add(la);
  51.         l.add(lb);
  52.         l.add(lc);
  53.         l.add(ld);
  54.         l.add(le);
  55.  
  56.         return l;
  57.     }
  58.     public JPanel createTextgrid()
  59.     {
  60.         JPanel tg = new JPanel(new GridLayout(4,6));
  61.         //tg.setVgap(3);
  62.  
  63.         w1 = new JLabel("One");
  64.         w2 = new JLabel("Two");
  65.         w3 = new JLabel("Three");
  66.         w4 = new JLabel("Four");
  67.  
  68.         atf = new JTextField(AREA);
  69.         atf.setEditable(true);
  70.         btf = new JTextField(AREA);
  71.         btf.setEditable(true);
  72.         ctf = new JTextField(AREA);
  73.         ctf.setEditable(false);
  74.         dtf = new JTextField(AREA);
  75.         dtf.setEditable(false);
  76.         etf = new JTextField(AREA);
  77.         etf.setEditable(false);
  78.         ftf = new JTextField(AREA);
  79.         ftf.setEditable(true);
  80.         gtf = new JTextField(AREA);
  81.         gtf.setEditable(true);
  82.         htf = new JTextField(AREA);
  83.         htf.setEditable(false);
  84.         itf = new JTextField(AREA);
  85.         itf.setEditable(false);
  86.         jtf = new JTextField(AREA);
  87.         jtf.setEditable(false);
  88.         ktf = new JTextField(AREA);
  89.         ktf.setEditable(true);
  90.         ltf = new JTextField(AREA);
  91.         ltf.setEditable(true);
  92.         mtf = new JTextField(AREA);
  93.         mtf.setEditable(false);
  94.         ntf = new JTextField(AREA);
  95.         ntf.setEditable(false);
  96.         otf = new JTextField(AREA);
  97.         otf.setEditable(false);
  98.         ptf = new JTextField(AREA);
  99.         ptf.setEditable(true);
  100.         qtf = new JTextField(AREA);
  101.         qtf.setEditable(true);
  102.         rtf = new JTextField(AREA);
  103.         rtf.setEditable(false);
  104.         stf = new JTextField(AREA);
  105.         stf.setEditable(false);
  106.         ttf = new JTextField(AREA);
  107.         ttf.setEditable(false);
  108.  
  109.         tg.add(w1);
  110.         tg.add(atf);
  111.         tg.add(btf);
  112.         tg.add(ctf);
  113.         tg.add(dtf);
  114.         tg.add(etf);
  115.         tg.add(w2);
  116.         tg.add(ftf);
  117.         tg.add(gtf);
  118.         tg.add(htf);
  119.         tg.add(itf);
  120.         tg.add(jtf);
  121.         tg.add(w3);
  122.         tg.add(ktf);
  123.         tg.add(ltf);
  124.         tg.add(mtf);
  125.         tg.add(ntf);
  126.         tg.add(otf);
  127.         tg.add(w4);
  128.         tg.add(ptf);
  129.         tg.add(qtf);
  130.         tg.add(rtf);
  131.         tg.add(stf);
  132.         tg.add(ttf);
  133.  
  134.         return tg;
  135.     }
  136.     protected JComponent createButtonPanel()
  137.     {
  138.         JPanel bp = new JPanel(new FlowLayout());
  139.  
  140.         JButton calcbutton = new JButton("Calculate");
  141.         calcbutton.setActionCommand(CALC);
  142.         calcbutton.addActionListener(this);
  143.  
  144.         JButton exitbutton = new JButton("Exit");
  145.         exitbutton.setActionCommand(EXIT);
  146.         exitbutton.addActionListener(this);
  147.  
  148.         bp.add(calcbutton);
  149.         bp.add(exitbutton);
  150.  
  151.         return bp;
  152.     }
  153.     public void actionPerformed(ActionEvent event)
  154.     {
  155.         double a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,gross,paytotal,monthly;
  156.         String cmd = event.getActionCommand();
  157.  
  158.         a = Double.parseDouble(atf.getText());
  159.         a = a * RATE;
  160.         b = Double.parseDouble(btf.getText());
  161.         c = a+b;
  162.         f = Double.parseDouble(ftf.getText());
  163.         f = f * RATE;
  164.         g = Double.parseDouble(gtf.getText());
  165.         h = f+g;
  166.         k = Double.parseDouble(ktf.getText());
  167.         k = k * RATE;
  168.         l = Double.parseDouble(ltf.getText());
  169.         m = k+l;
  170.         p = Double.parseDouble(ptf.getText());
  171.         p = p * RATE;
  172.         q = Double.parseDouble(qtf.getText());
  173.         r = p+q;
  174.  
  175.         ctf.setText(twoDigits.format(c));
  176.         htf.setText(twoDigits.format(h));
  177.         mtf.setText(twoDigits.format(m));
  178.         rtf.setText(twoDigits.format(r));
  179.  
  180.         d = (c * TAX);
  181.         i = (h * TAX);
  182.         n = (m * TAX);
  183.         s = (r * TAX);
  184.  
  185.         dtf.setText(twoDigits.format(d));
  186.         itf.setText(twoDigits.format(i));
  187.         ntf.setText(twoDigits.format(n));
  188.         stf.setText(twoDigits.format(s));
  189.  
  190.         e = c-d;
  191.         j = h-i;
  192.         o = m-n;
  193.         t = r-s;
  194.  
  195.         etf.setText(twoDigits.format(e));
  196.         jtf.setText(twoDigits.format(j));
  197.         otf.setText(twoDigits.format(o));
  198.         ttf.setText(twoDigits.format(t));
  199.  
  200.         if(CALC.equals(cmd))
  201.         {
  202.             gross = c+h+m+r;
  203.             paytotal = e+j+o+t;
  204.             monthly = paytotal+b+g+l+q;
  205.  
  206.             JOptionPane.showMessageDialog(controllingFrame, "Monthly Gross: $"+gross+nline+"Montly Paycheck Total: $"+paytotal+nline+"Montly Income: $"+monthly, "Calculations", JOptionPane.INFORMATION_MESSAGE);
  207.         }
  208.         else
  209.         {
  210.             System.exit(0);
  211.         }
  212.     }
  213.     public static void createAndShowGUI()
  214.     {
  215.         JFrame frame = new JFrame("Paycheck Simple Calculations");
  216.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  217.         frame.getContentPane();
  218.         frame.pack();
  219.         frame.setSize(700,700);
  220.         frame.setVisible(true);
  221.  
  222.     }
  223.     public static void main(String[] args)
  224.     {
  225.         javax.swing.SwingUtilities.invokeLater(new Runnable()
  226.         {
  227.             public void run()
  228.             {
  229.                 createAndShowGUI();
  230.             }
  231.         });
  232.     }
  233. }
  234.  
The parts listed in //comments are the three problems I couldn't figure out...I just run the program without it to see if it'd work...Please don't make fun of my programming...i t's how I taught myself. Lol.
Dec 5 '08 #4
JosAH
11,448 Recognized Expert MVP
Your code just creates an empty JFrame and displays it in the createAndShowGU I() method.

kind regards,

Jos
Dec 5 '08 #5
hsn
237 New Member
well, that is common issue with new programmers, your createAndShowGU I() function doesn't call any function. so your main call that function and then stops.

kind regards
hsn
Dec 5 '08 #6
Sarii
7 New Member
Okay, figured that problem out...but it doesn't do exactly what I want it to do...

I want it to be where the user inputs the number of hours worked in a week, their tips accumulated through the week, and the rate is stored in the program where it'll calculate the gross, take out a percent estimated as the tax and show net pay for the week. Then when you want to, you can hit the calculate button and make it show gross amount for the month, and net pay for the month. My buttons aren't working right and well, nothing is working right...I have the code right to where my components will show but I can't get it to be where I want it to be, kinda...
Dec 8 '08 #7
JosAH
11,448 Recognized Expert MVP
@Sarii
Well, that was kinda vague; please first make up your mind then formulate a clear description of what you want and how you want to do it; give it a try and then, if you're stuck, come back here.

kind regards,

Jos
Dec 8 '08 #8
Sarii
7 New Member
New problems...

My buttons don't exactly work. My fields are empty, so I understand my calculate button not working, but why wouldn't the exit button work? I fixed it to where all my required fields have a starting entry of 0, but it just confuses me on why my exit button wouldn't work.
Dec 11 '08 #9

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

Similar topics

5
3029
by: BStorm | last post by:
I have a transaction log file where the DataSet table's Description column is actually delimited into "subcolumns" based upon the transaction id. I would like to parse these into separate fields for reporting purposes and am wondering if anyone knows if this is easily accomplished using the .NET version of Crystal Reports? For example, the description column may be reporting on a dataentry error as follows: TXNCODE: 1010001
0
1292
by: Ken Dopierala Jr. | last post by:
Hi, I know this post will be considered off-topic. There are a lot of good coders in these groups and I'm hoping someone can help me out. This is what I'm working on. I used to use the webservice.htc alot, but now I have to code for Netscape and Mozilla and it didn't work. This was a good thing, the webservice.htc would choke if you sent back things like arraylists so I wrote my own wrapper. No matter what you send (dataset, array,...
3
1287
by: RallyDSM | last post by:
Pre STory - I've had a lot of problems with this program, and I just added the last part of it (the add item code) and now an older part of the program crashes. Public Structure Stocks Public stockName As String Public numShares As Double Public datePurchased As String Public purchasePrice As Double Public currentPrice As Double
4
12454
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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
10105
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
9185
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
6876
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
5542
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...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
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
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.