java - writing program in eclipse causes errors in command prompt -
so i'm writing program class , needs runnable via command prompt. ie javac filename.java java filename. wrote code in eclipse why i'm having trouble. code follows:
import javax.swing.japplet; import javax.swing.jbutton; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jlabel; import javax.swing.swingconstants; import com.jgoodies.forms.layout.formlayout; import com.jgoodies.forms.layout.columnspec; import com.jgoodies.forms.factories.formfactory; import com.jgoodies.forms.layout.rowspec; import java.awt.font; public class qa extends japplet implements actionlistener{ int y=0; int x=0; int a=0; int b=0; static int q=-1; jbutton btnyes = new jbutton("yes"); jbutton btnno = new jbutton("no"); static jlabel lblnewlabel = new jlabel("use buttons answer question: pizza?"); public qa() { getcontentpane().setlayout(new formlayout(new columnspec[] { columnspec.decode("220px"), formfactory.unrelated_gap_colspec, columnspec.decode("220px"),}, new rowspec[] { rowspec.decode("97px"), rowspec.decode("50px"), rowspec.decode("73px"), rowspec.decode("42px"),})); btnyes.setfont(new font("tahoma", font.plain, 10)); getcontentpane().add(btnyes, "1, 4, right, fill"); btnyes.setactioncommand("yes"); btnyes.addactionlistener(this); btnno.setfont(new font("tahoma", font.plain, 10)); getcontentpane().add(btnno, "3, 4, left, fill"); btnno.setactioncommand("no"); btnno.addactionlistener(this); lblnewlabel.sethorizontalalignment(swingconstants.center); getcontentpane().add(lblnewlabel, "1, 2, 3, 1, fill, fill"); } public void actionperformed(actionevent evt) { object cmd = evt.getactioncommand(); if (cmd == "yes") { ++q; } else if (cmd == "no") { ++q; } } } }
the errors along lines of:
c:\users\*****\desktop>javac qa.java qa.java:8: error: package com.jgoodies.forms.layout not exist import com.jgoodies.forms.layout.formlayout; ^ qa.java:9: error: package com.jgoodies.forms.layout not exist import com.jgoodies.forms.layout.columnspec; ^ qa.java:10: error: package com.jgoodies.forms.factories not exist import com.jgoodies.forms.factories.formfactory; ^ qa.java:11: error: package com.jgoodies.forms.layout not exist import com.jgoodies.forms.layout.rowspec; ^ qa.java:32: error: cannot find symbol getcontentpane().setlayout(new formlayout(new columnspec[] { ^ symbol: class formlayout location: class qa qa.java:32: error: cannot find symbol getcontentpane().setlayout(new formlayout(new columnspec[] { ^ symbol: class columnspec location: class qa qa.java:33: error: cannot find symbol columnspec.decode("220px"), ^ symbol: variable columnspec location: class qa qa.java:34: error: cannot find symbol formfactory.unrelated_gap_colspec, ^ symbol: variable formfactory location: class qa qa.java:35: error: cannot find symbol columnspec.decode("220px"),}, ^ symbol: variable columnspec location: class qa qa.java:36: error: cannot find symbol new rowspec[] { ^ symbol: class rowspec location: class qa qa.java:37: error: cannot find symbol rowspec.decode("97px"), ^ symbol: variable rowspec location: class qa qa.java:38: error: cannot find symbol rowspec.decode("50px"), ^ symbol: variable rowspec location: class qa qa.java:39: error: cannot find symbol rowspec.decode("73px"), ^ symbol: variable rowspec location: class qa qa.java:40: error: cannot find symbol rowspec.decode("42px"),})); ^ symbol: variable rowspec location: class qa 14 errors
is there can do? help!
you're missing jgoodies forms jar classpath. can download here
to compile:
javac .;forms-1.2.1.jar qa.java
to run:
appletviewer my-qa-test.html
where html document contains applet tag
<applet code="qa.class" width=400 height=75 arhive="forms-1.2.1.jar"> </applet>
aside: when comparing string
contents, use string#equals
==
operator compares object references. in case apply separation of concerns using anonymous actionlistener
classes:
btnyes.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { q++; } });
Comments
Post a Comment