2 questions(an error and line breakpoint?)
ok i made this and when i try to run it i get a compilation error and i have a question about something im seeing on eclipse
Code Java:
package wlodmgcalc;
import javax.swing.*;
import java.awt.*;
import java.awt.Event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class wlocalc extends JFrame implements ActionListener, ItemListener {
public wlocalc() {
super("Dmg Calculator");
setSize(200, 210);
setBackground(Color.white);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
setLayout(flow);
JPanel row1 = new JPanel();
JLabel atkLabel = new JLabel("Attack:");
row1.add(atkLabel);
JTextField atk = new JTextField(7);
row1.add(atk);
add(row1);
JPanel row2 = new JPanel();
JLabel elementLabel = new JLabel("Element:");
row2.add(elementLabel);
String[] elements = { "Wind", "Fire", "Water", "Earth" };
JComboBox elementBox = new JComboBox(elements);
elementBox.setSelectedIndex(2);
row2.add(elementBox);
add(row2);
JPanel row3 = new JPanel();
FlowLayout flowbutton = new FlowLayout(FlowLayout.CENTER, 50, 10);
row3.setLayout(flowbutton);
JButton calculate = new JButton("Calculate");
calculate.addActionListener(this);
row3.add(calculate);
add(row3);
JPanel row4 = new JPanel();
JLabel totalLabel = new JLabel("Damage: ");
JTextField damageTotal = new JTextField(5);
row4.add(totalLabel);
row4.add(damageTotal);
damageTotal.setEditable(false);
add(row4);
pack();
setVisible(true);
atk.addItemListener(this);
}
public void actionPerformed(ActionEvent event) {
String atkNumber = atk.getActionCommand();
String pressed = event.getActionCommand();
if (pressed.equals("Calculate")) {
System.out.println(atkNumber);
}
}
public static void main(String[] args) {
wlocalc dmg = new wlocalc();
}
}
the error i get is
Quote:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at wlodmgcalc.wlocalc.main(wlocalc.java:65)
and the other question i have is 1 line in eclipse has a little purple dot next to it and says
"Line Breakpoint:wlocalc [line:24] - wlocalc()"
no idea what that means and i dont see anything wrong with line 65 either so im pretty lost. any help is very much appreciated :D thanks
Re: 2 questions(an error and line breakpoint?)
I'd recommend compiling from the command line until you understand these kinds of messages. Which line is number 65? Apparently it contains a compiler error. And have you googled "eclipse breakpoint" or something similar?
Re: 2 questions(an error and line breakpoint?)
ill google the breakpoint and see what comes up
line 65 it says is
public static void main(String[] args) {
Re: 2 questions(an error and line breakpoint?)
Quote:
Originally Posted by
derekxec
ill google the breakpoint and see what comes up
line 65 it says is
public static void main(String[] args) {
You need to get the actual compiler error, which eclipse should give you before you even try to run anything. But if you can't figure out eclipse, I seriously recommend compiling from the command line.
Re: 2 questions(an error and line breakpoint?)
usually i get some errors or so but when i try to run thats what comes up and the program terminates and i have some markers showing but not sure how to fix them...im having trouble getting how to make a gui work with my program :( its not getting through my thick skull lol
Re: 2 questions(an error and line breakpoint?)
wlocalc.java:7: cannot find symbol
symbol: class ItemListener
public class wlocalc extends JFrame implements ActionListener, ItemListener {
^
wlocalc.java:52: cannot find symbol
symbol : method addItemListener(wlocalc)
location: class javax.swing.JTextField
atk.addItemListener(this);
^
wlocalc.java:56: cannot find symbol
symbol : variable atk
location: class wlocalc
String atkNumber = atk.getActionCommand();
^
3 errors
Those are the errors I get. I don't know what you are doing.
Re: 2 questions(an error and line breakpoint?)
weird i dont see any of that one mine usually i get red X or so on the left side with errors but none there now lol
the linebreak i found was cause i went into debug mode to try it out and i guess the program stopped there but i toggled it off maybe thats why im having so much problems with it
Re: 2 questions(an error and line breakpoint?)
I got those errors when compiling on the command line. Something you were advised to do twice and totally ignored.
Re: 2 questions(an error and line breakpoint?)
when i tried on command line i got an "is not recognized as an internal or external command operable program or batch file" and it wouldnt do anything
Re: 2 questions(an error and line breakpoint?)
Quote:
Originally Posted by
derekxec
when i tried on command line i got an "is not recognized as an internal or external command operable program or batch file" and it wouldnt do anything
Which means you haven't set your environment variables to use Java yet.
Have a look how to do that here: Configure Java environment on Windows
Hope that helps,
Goldest
Re: 2 questions(an error and line breakpoint?)
i did that but maybe i didnt do correctly ill double check it to make sure but even when i go to the directory that the compiler is in and put all there it says it too but if i run a .jar like java -jar heh.jar it runs fine?
ill double check and thanks for all the info :D
one other question if you all dont mind :)
import java.awt.*
this doesn't add all of the java.awt. stuff?
Re: 2 questions(an error and line breakpoint?)
Quote:
Originally Posted by
derekxec
when i go to the directory that the compiler is in and put all there
Do not place your Java files in the Java installation directory. Keep your files elsewhere. If you have set up the environment variables correctly you can compile and run your Java programs anywhere on the computer.
Quote:
import java.awt.*
this doesn't add all of the java.awt. stuff?
The * is not recursive. Therefore any classes in the event subpackage (or any other subpackage) will not be imported. Personally I dislike using the * and add an explicit import statement for each class I use. One reason is:
Code java:
import java.sql.*;
import java.util.*;
class Kaboom {
Date d; // error due to Date class in both sql and util packages.
}
Re: 2 questions(an error and line breakpoint?)
ah thank you that explains the first error :D i guess ill stop using the * too and save some hassle thanks a lot :D
im checking the path out right now hopefully i just made some mistake in the path or so
Re: 2 questions(an error and line breakpoint?)
In my experience, clashes don't happen very often, and when they do (e.g. you need to use both classes, or as in the case above), you just have to explicitly qualify one class (usually the one you use least). With wildcard imports, you can add an explicit import for the clashing type you actually use (or use most often if you use both), and explicitly qualify the clashing type you use least. The compiler warns you when there's an unresolved name clash, so it's no problem.
For example, if you use java.util.Date more in the code than java.sql.date, you could do this:
Code java:
import java.sql.*;
import java.util.*;
import java.util.Date; // explicitly import the class you use (or use most often) when there's a name clash.
class NoProblem {
Date d; // by default will use java.util.Date because of explicit import
java.sql.Date s; // to use java.sql.Date you need to explicitly specify its package
}
Of course, this is only needed when you're using many classes from a single package and there's a name clash with another package, and you want to avoid a rash of unnecessary import statements. The explicit import of one class and the explicit qualification of the other make it pretty clear which is which in the code.
Most decent IDEs will have a setting where you can specify the number of separate imports from a single package at which the separate import statements will replaced by a single wildcard import. Wildcard imports are optional, but they're provided for a good reason.