Shelnutt2
05-12-2006, 01:50 AM
I've read my Java for dumies guide. I think I am almost finished now, but here is my problem. I have figuered out how to get the number the user entered. Yet I can't get it to put it into my other Label. Here is my whole code.
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.lang.*;
class creditsGUI extends Applet { //litst of boxes
Label Header;
TextField choice_LA1;
TextField choice_MM1;
TextField choice_Science1;
TextField choice_WH1;
TextField choice_AH1;
TextField choice_Economics1;
TextField choice_AG1;
TextField choice_Arts1;
TextField choice_LM1;
TextField choice_PF1;
TextField choice_PE1;
TextField choice_Electives1;
Label Label_LA;
Label Label_MM;
Label Label_Science;
Label Label_WH;
Label Label_AH;
Label Label_Economics;
Label Label_AG;
Label Label_Arts;
Label Label_LM;
Label Label_PF;
Label Label_PE;
Label Label_Elective;
Label heading1;
Label LA_needed;
Label MM_needed;
Label Science_needed;
Label WH_needed;
Label AH_needed;
Label Economics_needed;
Label AG_needed;
Label Arts_needed;
Label LM_needed;
Label PF_needed;
Label PE_needed;
Label Electives_needed;
Label heading2;
Label heading3;
Label heading4;
int creditsn, credits, LAC, MMC, ScienceC, WHC, AHC; //varibles I will use
int EconomicsC, AGC, ArtsC, LMSC, PFC, PEC, ElectivesC;
int Economics, AG, Arts, LMS, PF, PE, Electives;
public void init() {
creditsGUILayout customLayout = new creditsGUILayout();
setFont(new Font("Helvetica", Font.PLAIN, 12));
setLayout(customLayout);
Header = new Label("This program will tell you how many credits you need to graduate"); //Title
add(Header);
choice_LA1 = new TextField("0"); //First textField on the left
add(choice_LA1);
int LAC = Integer.parseInt(choice_LA1.getText()); //how I am getting the user entered integer and making it a varible
choice_MM1 = new TextField("0");
add(choice_MM1);
choice_Science1 = new TextField("0");
add(choice_Science1);
choice_WH1 = new TextField("0");
add(choice_WH1);
choice_AH1 = new TextField("0");
add(choice_AH1);
choice_Economics1 = new TextField("0");
add(choice_Economics1);
choice_AG1 = new TextField("0");
add(choice_AG1);
choice_Arts1 = new TextField("0");
add(choice_Arts1);
choice_LM1 = new TextField("0");
add(choice_LM1);
choice_PF1 = new TextField("0");
add(choice_PF1);
choice_PE1 = new TextField("0");
add(choice_PE1);
choice_Electives1 = new TextField("0"); //Last textField on the left
add(choice_Electives1);
Label_LA = new Label("language Arts Credits"); //First label on the left, next to textFields
add(Label_LA);
Label_MM = new Label("Mathematics credits");
add(Label_MM);
Label_Science = new Label("Science credits");
add(Label_Science);
Label_WH = new Label("World History credits");
add(Label_WH);
Label_AH = new Label("American History credits");
add(Label_AH);
Label_Economics = new Label("Economics credits");
add(Label_Economics);
Label_AG = new Label("American Goverment credits");
add(Label_AG);
Label_Arts = new Label("Practical/Fine Art credits");
add(Label_Arts);
Label_LM = new Label("Life Management Skill credits");
add(Label_LM);
Label_PF = new Label("Personal Fitness credits");
add(Label_PF);
Label_PE = new Label("Personal Education credits");
add(Label_PE);
Label_Elective = new Label("Elective credits"); //Last label on the left, next to textFields
add(Label_Elective);
heading1 = new Label("These are the credits you still"); //Label above labels on the right
add(heading1);
LA_needed = new Label(LAC); // First label underneath heading label on the right
add(LA_needed);
MM_needed = new Label("LAC");
add(MM_needed);
Science_needed = new Label("0");
add(Science_needed);
WH_needed = new Label("0");
add(WH_needed);
AH_needed = new Label("0");
add(AH_needed);
Economics_needed = new Label("0");
add(Economics_needed);
AG_needed = new Label("0");
add(AG_needed);
Arts_needed = new Label("0");
add(Arts_needed);
LM_needed = new Label("0");
add(LM_needed);
PF_needed = new Label("0");
add(PF_needed);
PE_needed = new Label("0");
add(PE_needed);
Electives_needed = new Label("0"); //Last label on the right
add(Electives_needed);
heading2 = new Label("need for each subject");
add(heading2);
heading3 = new Label("Enter the number");
add(heading3);
heading4 = new Label("of credits you have");
add(heading4);
setSize(getPreferredSize());
}
public static void main(String args[]) {
creditsGUI applet = new creditsGUI();
Frame window = new Frame("creditsGUI");
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
applet.init();
window.add("Center", applet);
window.pack();
window.setVisible(true);
}
}
class creditsGUILayout implements LayoutManager {
public creditsGUILayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 975 + insets.left + insets.right;
dim.height = 891 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+304,insets.top+8,408,32); }
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+136,72,24) ;}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+168,72,24) ;}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+200,72,24) ;}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+232,72,24) ;}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+264,72,24) ;}
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+296,72,24) ;}
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+328,72,24) ;}
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+360,72,24) ;}
c = parent.getComponent(9);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+392,72,24) ;}
c = parent.getComponent(10);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+424,72,24) ;}
c = parent.getComponent(11);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+456,72,24) ;}
c = parent.getComponent(12);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+488,72,24) ;}
c = parent.getComponent(13);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+136,184,24); }
c = parent.getComponent(14);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+168,184,24); }
c = parent.getComponent(15);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+200,184,24); }
c = parent.getComponent(16);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+232,184,24); }
c = parent.getComponent(17);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+264,184,24); }
c = parent.getComponent(18);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+296,184,24); }
c = parent.getComponent(19);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+328,184,24); }
c = parent.getComponent(20);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+360,184,24); }
c = parent.getComponent(21);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+392,184,24); }
c = parent.getComponent(22);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+424,184,24); }
c = parent.getComponent(23);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+456,184,24); }
c = parent.getComponent(24);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+488,184,24); }
c = parent.getComponent(25);
if (c.isVisible()) {c.setBounds(insets.left+592,insets.top+64,216,24) ;}
c = parent.getComponent(26);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+136,72,24) ;}
c = parent.getComponent(27);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+168,72,24) ;}
c = parent.getComponent(28);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+200,72,24) ;}
c = parent.getComponent(29);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+232,72,24) ;}
c = parent.getComponent(30);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+264,72,24) ;}
c = parent.getComponent(31);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+296,72,24) ;}
c = parent.getComponent(32);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+328,72,24) ;}
c = parent.getComponent(33);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+360,72,24) ;}
c = parent.getComponent(34);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+392,72,24) ;}
c = parent.getComponent(35);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+424,72,24) ;}
c = parent.getComponent(36);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+456,72,24) ;}
c = parent.getComponent(37);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+488,72,24) ;}
c = parent.getComponent(38);
if (c.isVisible()) {c.setBounds(insets.left+592,insets.top+88,216,24) ;}
c = parent.getComponent(39);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+56,192,24);}
c = parent.getComponent(40);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+80,192,24);}
}
}
I know, I know I need loops.
choice_LA1 = new TextField("0"); //First textField on the left
add(choice_LA1);
int LAC = Integer.parseInt(choice_LA1.getText()); //how I am getting the user entered integer and making it a varible
LA_needed = new Label(LAC); // First label underneath heading label on the right
add(LA_needed);
When I try to do that, so it will print what you have entered in the box for Language arts credits, I get the error "cannot find symbol constructor Label(int)"
What am I doing wrong?
Thanks
edit:
I am getting some help here (http://www.ocforums.com/showthread.php?p=4488474#post4488474)to.
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.lang.*;
class creditsGUI extends Applet { //litst of boxes
Label Header;
TextField choice_LA1;
TextField choice_MM1;
TextField choice_Science1;
TextField choice_WH1;
TextField choice_AH1;
TextField choice_Economics1;
TextField choice_AG1;
TextField choice_Arts1;
TextField choice_LM1;
TextField choice_PF1;
TextField choice_PE1;
TextField choice_Electives1;
Label Label_LA;
Label Label_MM;
Label Label_Science;
Label Label_WH;
Label Label_AH;
Label Label_Economics;
Label Label_AG;
Label Label_Arts;
Label Label_LM;
Label Label_PF;
Label Label_PE;
Label Label_Elective;
Label heading1;
Label LA_needed;
Label MM_needed;
Label Science_needed;
Label WH_needed;
Label AH_needed;
Label Economics_needed;
Label AG_needed;
Label Arts_needed;
Label LM_needed;
Label PF_needed;
Label PE_needed;
Label Electives_needed;
Label heading2;
Label heading3;
Label heading4;
int creditsn, credits, LAC, MMC, ScienceC, WHC, AHC; //varibles I will use
int EconomicsC, AGC, ArtsC, LMSC, PFC, PEC, ElectivesC;
int Economics, AG, Arts, LMS, PF, PE, Electives;
public void init() {
creditsGUILayout customLayout = new creditsGUILayout();
setFont(new Font("Helvetica", Font.PLAIN, 12));
setLayout(customLayout);
Header = new Label("This program will tell you how many credits you need to graduate"); //Title
add(Header);
choice_LA1 = new TextField("0"); //First textField on the left
add(choice_LA1);
int LAC = Integer.parseInt(choice_LA1.getText()); //how I am getting the user entered integer and making it a varible
choice_MM1 = new TextField("0");
add(choice_MM1);
choice_Science1 = new TextField("0");
add(choice_Science1);
choice_WH1 = new TextField("0");
add(choice_WH1);
choice_AH1 = new TextField("0");
add(choice_AH1);
choice_Economics1 = new TextField("0");
add(choice_Economics1);
choice_AG1 = new TextField("0");
add(choice_AG1);
choice_Arts1 = new TextField("0");
add(choice_Arts1);
choice_LM1 = new TextField("0");
add(choice_LM1);
choice_PF1 = new TextField("0");
add(choice_PF1);
choice_PE1 = new TextField("0");
add(choice_PE1);
choice_Electives1 = new TextField("0"); //Last textField on the left
add(choice_Electives1);
Label_LA = new Label("language Arts Credits"); //First label on the left, next to textFields
add(Label_LA);
Label_MM = new Label("Mathematics credits");
add(Label_MM);
Label_Science = new Label("Science credits");
add(Label_Science);
Label_WH = new Label("World History credits");
add(Label_WH);
Label_AH = new Label("American History credits");
add(Label_AH);
Label_Economics = new Label("Economics credits");
add(Label_Economics);
Label_AG = new Label("American Goverment credits");
add(Label_AG);
Label_Arts = new Label("Practical/Fine Art credits");
add(Label_Arts);
Label_LM = new Label("Life Management Skill credits");
add(Label_LM);
Label_PF = new Label("Personal Fitness credits");
add(Label_PF);
Label_PE = new Label("Personal Education credits");
add(Label_PE);
Label_Elective = new Label("Elective credits"); //Last label on the left, next to textFields
add(Label_Elective);
heading1 = new Label("These are the credits you still"); //Label above labels on the right
add(heading1);
LA_needed = new Label(LAC); // First label underneath heading label on the right
add(LA_needed);
MM_needed = new Label("LAC");
add(MM_needed);
Science_needed = new Label("0");
add(Science_needed);
WH_needed = new Label("0");
add(WH_needed);
AH_needed = new Label("0");
add(AH_needed);
Economics_needed = new Label("0");
add(Economics_needed);
AG_needed = new Label("0");
add(AG_needed);
Arts_needed = new Label("0");
add(Arts_needed);
LM_needed = new Label("0");
add(LM_needed);
PF_needed = new Label("0");
add(PF_needed);
PE_needed = new Label("0");
add(PE_needed);
Electives_needed = new Label("0"); //Last label on the right
add(Electives_needed);
heading2 = new Label("need for each subject");
add(heading2);
heading3 = new Label("Enter the number");
add(heading3);
heading4 = new Label("of credits you have");
add(heading4);
setSize(getPreferredSize());
}
public static void main(String args[]) {
creditsGUI applet = new creditsGUI();
Frame window = new Frame("creditsGUI");
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
applet.init();
window.add("Center", applet);
window.pack();
window.setVisible(true);
}
}
class creditsGUILayout implements LayoutManager {
public creditsGUILayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 975 + insets.left + insets.right;
dim.height = 891 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+304,insets.top+8,408,32); }
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+136,72,24) ;}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+168,72,24) ;}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+200,72,24) ;}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+232,72,24) ;}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+264,72,24) ;}
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+296,72,24) ;}
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+328,72,24) ;}
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+360,72,24) ;}
c = parent.getComponent(9);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+392,72,24) ;}
c = parent.getComponent(10);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+424,72,24) ;}
c = parent.getComponent(11);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+456,72,24) ;}
c = parent.getComponent(12);
if (c.isVisible()) {c.setBounds(insets.left+224,insets.top+488,72,24) ;}
c = parent.getComponent(13);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+136,184,24); }
c = parent.getComponent(14);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+168,184,24); }
c = parent.getComponent(15);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+200,184,24); }
c = parent.getComponent(16);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+232,184,24); }
c = parent.getComponent(17);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+264,184,24); }
c = parent.getComponent(18);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+296,184,24); }
c = parent.getComponent(19);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+328,184,24); }
c = parent.getComponent(20);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+360,184,24); }
c = parent.getComponent(21);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+392,184,24); }
c = parent.getComponent(22);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+424,184,24); }
c = parent.getComponent(23);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+456,184,24); }
c = parent.getComponent(24);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+488,184,24); }
c = parent.getComponent(25);
if (c.isVisible()) {c.setBounds(insets.left+592,insets.top+64,216,24) ;}
c = parent.getComponent(26);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+136,72,24) ;}
c = parent.getComponent(27);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+168,72,24) ;}
c = parent.getComponent(28);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+200,72,24) ;}
c = parent.getComponent(29);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+232,72,24) ;}
c = parent.getComponent(30);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+264,72,24) ;}
c = parent.getComponent(31);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+296,72,24) ;}
c = parent.getComponent(32);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+328,72,24) ;}
c = parent.getComponent(33);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+360,72,24) ;}
c = parent.getComponent(34);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+392,72,24) ;}
c = parent.getComponent(35);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+424,72,24) ;}
c = parent.getComponent(36);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+456,72,24) ;}
c = parent.getComponent(37);
if (c.isVisible()) {c.setBounds(insets.left+656,insets.top+488,72,24) ;}
c = parent.getComponent(38);
if (c.isVisible()) {c.setBounds(insets.left+592,insets.top+88,216,24) ;}
c = parent.getComponent(39);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+56,192,24);}
c = parent.getComponent(40);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+80,192,24);}
}
}
I know, I know I need loops.
choice_LA1 = new TextField("0"); //First textField on the left
add(choice_LA1);
int LAC = Integer.parseInt(choice_LA1.getText()); //how I am getting the user entered integer and making it a varible
LA_needed = new Label(LAC); // First label underneath heading label on the right
add(LA_needed);
When I try to do that, so it will print what you have entered in the box for Language arts credits, I get the error "cannot find symbol constructor Label(int)"
What am I doing wrong?
Thanks
edit:
I am getting some help here (http://www.ocforums.com/showthread.php?p=4488474#post4488474)to.