i have a project.it's a coffee shop program using jar please help on how to do it.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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.
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.
Last edited by Json; December 22nd, 2009 at 11:09 AM. Reason: Lets try some code tags.
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
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.