i have a project.it's a coffee shop program using jar please help on how to do it.
Printable View
i have a project.it's a coffee shop program using jar please help on how to do it.
You can show more detailed information about you project.
Code :import java.awt.*; import javax.swing.*; public class coffee { private JFrame f; private JButton b1, b2, b3; private JTextArea tNum1, tNum2, tNum3, tNum4; private JRadioButton rb1, rb2, rb3, rb4, rb5, rb6; private JPanel p1, p2, p3; private ButtonGroup bg; public coffee() { f = new JFrame(); bg = new ButtonGroup(); b1 = new JButton("Compute Price"); b2 = new JButton("Clear"); b3 = new JButton("Exit"); tNum1 = new JTextArea(); tNum2 = new JTextArea(); tNum3 = new JTextArea(); tNUm4 = new JTextArea(); rb1 = new JRadioButton("Cappuccino = P150"); rb2 = new JRadioButton("Cafe Latte = P200"); rb3 = new JRadioButton("Cafe Macchiato = P300"); rb4 = new JRadioButton("Mocha = P400"); bCompute = new JButton("TOTAL"); tNum1.setColumns(2); tNum2.setColumns(2); tNum3.setColumns(2); bCompute.setActionCommand("TOTAL"); rb5 = new JRadioButton("Dine in"); rb6 = new JRadioButton("Take out"); bg.add(rb5); bg.add(rb6); } public void launchWindow() { p1 = new JPanel(new GridLayout(4,3)); p1.add(b1); p1.add(b2); p1.add(b3); p2 = new JPanel(new GridLayout(4,1)); p2.add(rb1); p1.add(tNum1); p2.add(rb2); p2.add(tNum2); p2.add(rb3); p3.add(tNum3); p2.add(rb4); p3.add(tNum4); fCompute.add(p1); fCompute.add(p2); fCompute.add(p3); fCompute.add(bCompute); fCompute.pack(); fCompute.setVisible(true); fCompute.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)); p3 = new JPanel(new GridLayout(4,2)); f.add(p1, BorderLayout.EAST); f.add(p2, BorderLayout.WEST); f.setSize(600,400); f.setVisible(true); } public void actionPerformed(ActionEvent e) { int num1, num2, sum; String sSum; num1 = Integer.parseInt(tNum1.getText()); num2 = Integer.parseInt(tNum2.getText()); num3 = Integer.parseInt(tNum3.getText()); sum = num1 + num2 + num3; Sum = Integer.toString(sum); tNum3.setText(sSum); } public static void main(String args[]) { coffee guiApp = new coffee(); guiApp.launchWindow(); guiApp.f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); } }
THIS IS MY WORK... but im having an error on the 69 line. it says unexpected... can u help me please. my project is a coffee shop when you choose the menu there are prices and it computes to show the total amount.
What IDE are you using, if any?
I just pasted this into eclipse, and errors come way before line 69.
Anyways; other than typos like tNUm4 instead of tNum4, you are:
-using undeclared vars, bCompute and fCompute.
-getting a tonnes of null pointers p3, p4 are used before instantiated, there might be more (couldnt be arsed to check).
I doubt this code is written by you. I cant see how you would not catch the simple tNUm4 mistake. Unless you are writing in notepad that is.
Even so, if you have skill enough to write this code, you should also have skill enough to catch a nullpointer, which is a result from miss instantiating, which suggest that the code is not yours.
The code could very well be his, I still forget to instantiate variables before using them sometimes, and who knows how many times I've misspelled something and not caught it :P
If you're not using an IDE, I would strongly recommend getting one. Eclipse and Netbeans are both really good Java IDE's that also happen to be free. I'd recommend Eclipse because that's the IDE I'm comfortable with, but from what I hear both IDE's are on fairly equal grounding.
Remember, Java is case-sensitive, i.e. "hello" is not the same as "Hello", which both are different from "HELLO".
You must always declare variables before they can be used, and the Java compiler will also require you to instantiate variables before you try to retrieve a value from them (there is no "default value").
Yes, it is very possible to forget it, I do it too all the time.
However, when you get the nullpointer report, plus the line number - dont you usually figure out what you have done wrong? The code dont strike me as "total beginner", certainly someone who knows how to instantiate.
Anyway, I might have been wrong. If that is the case, Im sorry.