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...
8 1999
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 - 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.
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
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. -
import java.io.*;
-
import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
import java.text.DecimalFormat;
-
import java.util.*;
-
import java.lang.*;
-
-
public class grid extends JPanel implements ActionListener
-
{
-
JFrame controllingFrame;
-
JTextField atf,btf,ctf,dtf,etf,ftf,gtf,htf,itf,jtf,ktf,ltf,mtf,ntf,otf,ptf,qtf,rtf,stf,ttf;
-
JLabel w,la,lb,lc,ld,le,w1,w2,w3,w4;
-
Container contentPane;
-
static final int AREA = 5;
-
static final double RATE = 5.00;
-
static final double TAX = 0.20;
-
private static String CALC = "calculate";
-
private static String EXIT = "exit";
-
private static String nline= "\n";
-
DecimalFormat twoDigits = new DecimalFormat("0.00");
-
-
public grid(JFrame f)
-
{
-
controllingFrame = f;
-
f.setLayout(new GridLayout(3,1));
-
//f.setVgap(5);
-
-
JPanel labels = createLabels();
-
JPanel textgrid = createTextgrid();
-
JComponent buttons = createButtonPanel();
-
-
add(labels);
-
add(textgrid);
-
add(buttons);
-
}
-
public JPanel createLabels()
-
{
-
JPanel l = new JPanel(new GridLayout(0,6));
-
//l.setVgap(3);
-
-
w = new JLabel("Week");
-
la = new JLabel("Hours");
-
lb = new JLabel("Tips");
-
lc = new JLabel("Gross");
-
ld = new JLabel("Taxes");
-
le = new JLabel("Net Pay");
-
-
l.add(w);
-
l.add(la);
-
l.add(lb);
-
l.add(lc);
-
l.add(ld);
-
l.add(le);
-
-
return l;
-
}
-
public JPanel createTextgrid()
-
{
-
JPanel tg = new JPanel(new GridLayout(4,6));
-
//tg.setVgap(3);
-
-
w1 = new JLabel("One");
-
w2 = new JLabel("Two");
-
w3 = new JLabel("Three");
-
w4 = new JLabel("Four");
-
-
atf = new JTextField(AREA);
-
atf.setEditable(true);
-
btf = new JTextField(AREA);
-
btf.setEditable(true);
-
ctf = new JTextField(AREA);
-
ctf.setEditable(false);
-
dtf = new JTextField(AREA);
-
dtf.setEditable(false);
-
etf = new JTextField(AREA);
-
etf.setEditable(false);
-
ftf = new JTextField(AREA);
-
ftf.setEditable(true);
-
gtf = new JTextField(AREA);
-
gtf.setEditable(true);
-
htf = new JTextField(AREA);
-
htf.setEditable(false);
-
itf = new JTextField(AREA);
-
itf.setEditable(false);
-
jtf = new JTextField(AREA);
-
jtf.setEditable(false);
-
ktf = new JTextField(AREA);
-
ktf.setEditable(true);
-
ltf = new JTextField(AREA);
-
ltf.setEditable(true);
-
mtf = new JTextField(AREA);
-
mtf.setEditable(false);
-
ntf = new JTextField(AREA);
-
ntf.setEditable(false);
-
otf = new JTextField(AREA);
-
otf.setEditable(false);
-
ptf = new JTextField(AREA);
-
ptf.setEditable(true);
-
qtf = new JTextField(AREA);
-
qtf.setEditable(true);
-
rtf = new JTextField(AREA);
-
rtf.setEditable(false);
-
stf = new JTextField(AREA);
-
stf.setEditable(false);
-
ttf = new JTextField(AREA);
-
ttf.setEditable(false);
-
-
tg.add(w1);
-
tg.add(atf);
-
tg.add(btf);
-
tg.add(ctf);
-
tg.add(dtf);
-
tg.add(etf);
-
tg.add(w2);
-
tg.add(ftf);
-
tg.add(gtf);
-
tg.add(htf);
-
tg.add(itf);
-
tg.add(jtf);
-
tg.add(w3);
-
tg.add(ktf);
-
tg.add(ltf);
-
tg.add(mtf);
-
tg.add(ntf);
-
tg.add(otf);
-
tg.add(w4);
-
tg.add(ptf);
-
tg.add(qtf);
-
tg.add(rtf);
-
tg.add(stf);
-
tg.add(ttf);
-
-
return tg;
-
}
-
protected JComponent createButtonPanel()
-
{
-
JPanel bp = new JPanel(new FlowLayout());
-
-
JButton calcbutton = new JButton("Calculate");
-
calcbutton.setActionCommand(CALC);
-
calcbutton.addActionListener(this);
-
-
JButton exitbutton = new JButton("Exit");
-
exitbutton.setActionCommand(EXIT);
-
exitbutton.addActionListener(this);
-
-
bp.add(calcbutton);
-
bp.add(exitbutton);
-
-
return bp;
-
}
-
public void actionPerformed(ActionEvent event)
-
{
-
double a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,gross,paytotal,monthly;
-
String cmd = event.getActionCommand();
-
-
a = Double.parseDouble(atf.getText());
-
a = a * RATE;
-
b = Double.parseDouble(btf.getText());
-
c = a+b;
-
f = Double.parseDouble(ftf.getText());
-
f = f * RATE;
-
g = Double.parseDouble(gtf.getText());
-
h = f+g;
-
k = Double.parseDouble(ktf.getText());
-
k = k * RATE;
-
l = Double.parseDouble(ltf.getText());
-
m = k+l;
-
p = Double.parseDouble(ptf.getText());
-
p = p * RATE;
-
q = Double.parseDouble(qtf.getText());
-
r = p+q;
-
-
ctf.setText(twoDigits.format(c));
-
htf.setText(twoDigits.format(h));
-
mtf.setText(twoDigits.format(m));
-
rtf.setText(twoDigits.format(r));
-
-
d = (c * TAX);
-
i = (h * TAX);
-
n = (m * TAX);
-
s = (r * TAX);
-
-
dtf.setText(twoDigits.format(d));
-
itf.setText(twoDigits.format(i));
-
ntf.setText(twoDigits.format(n));
-
stf.setText(twoDigits.format(s));
-
-
e = c-d;
-
j = h-i;
-
o = m-n;
-
t = r-s;
-
-
etf.setText(twoDigits.format(e));
-
jtf.setText(twoDigits.format(j));
-
otf.setText(twoDigits.format(o));
-
ttf.setText(twoDigits.format(t));
-
-
if(CALC.equals(cmd))
-
{
-
gross = c+h+m+r;
-
paytotal = e+j+o+t;
-
monthly = paytotal+b+g+l+q;
-
-
JOptionPane.showMessageDialog(controllingFrame, "Monthly Gross: $"+gross+nline+"Montly Paycheck Total: $"+paytotal+nline+"Montly Income: $"+monthly, "Calculations", JOptionPane.INFORMATION_MESSAGE);
-
}
-
else
-
{
-
System.exit(0);
-
}
-
}
-
public static void createAndShowGUI()
-
{
-
JFrame frame = new JFrame("Paycheck Simple Calculations");
-
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
frame.getContentPane();
-
frame.pack();
-
frame.setSize(700,700);
-
frame.setVisible(true);
-
-
}
-
public static void main(String[] args)
-
{
-
javax.swing.SwingUtilities.invokeLater(new Runnable()
-
{
-
public void run()
-
{
-
createAndShowGUI();
-
}
-
});
-
}
-
}
-
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.
JosAH 11,448
Recognized Expert MVP
Your code just creates an empty JFrame and displays it in the createAndShowGU I() method.
kind regards,
Jos
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
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...
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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,...
|
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
|
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
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |