• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Some more Java Help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Shelnutt2

Overclockers Team Content Editor
Joined
Jun 17, 2005
Location
/home/
Alright guys, after some delays I'm back to trying to write my *simple* java program. I just started working on a GUI, and applet. This is my first attempt and I'm really stuck here. I've created the first half of it, I've got it were the user can choose the amounts for each drop list. I'm using Java GUI Builder to visual build the GUI, then JCreator to modify the code. Now what I need to do is be able to (as seen in my command lien version) take what the user selects, subtract it from a defined number, then get the computer to print it out on the other side of the screen. How do I do this?

I'm modeling the applet after this command line version of my program.


Code:
import java.io.*;
import java.text.NumberFormat;

class Credits {

   public static void main(String args[]) throws IOException
   {

      BufferedReader keyboard =
         new BufferedReader(new InputStreamReader(System.in));
            Double creditsn, credits, LA, MM, Science, WH, AH;
            Double Economics, AG, Arts, LMS, PF, PE, Electives;
      
      System.out.print("How many Language Arts credits do you have?   ");
      LA = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many Mathematics credits do you have?   ");
      MM = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many Science credits do you have?   ");
      Science = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many World History credits do you have?   ");
      WH = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many American History credits do you have?   ");
      AH = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many Econimic credits do you have?   ");
      Economics = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many American Goverment credits do you have?   ");
      AG = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many Practical/Fine Art credits do you have?   ");
      Arts = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many Life Management Skill credits do you have?   ");
      LMS = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many Personal Fitness credits do you have?   ");
      PF = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many Pyscial Education credits do you have?   ");
      PE = Double.parseDouble(keyboard.readLine());
      
      System.out.print("How many Elective credits do you have?   ");
      Electives = Double.parseDouble(keyboard.readLine());
      
      creditsn = LA + MM + Science + WH + AH + Economics + AG + Arts + LMS + PF + PE + Electives;
            
      System.out.println("------------------------------");

           
      System.out.print("You need ");
      System.out.print(4 - LA );
      System.out.println(" more Language Arts credits");
      
      System.out.print("You need ");
      System.out.print(3 - MM );
      System.out.println(" more Mathematic credits");
      
      System.out.print("You need ");
      System.out.print(3 - Science );
      System.out.println(" more Science credits");
      
      System.out.print("You need ");
      System.out.print(1 - WH);
      System.out.println(" more World History credits");
      
      System.out.print("You need ");
      System.out.print(1 - AH );
      System.out.println(" more American History credits");
      
      System.out.print("You need ");
      System.out.print(.5 - Economics );
      System.out.println(" more Economics credits");
      
      System.out.print("You need ");
      System.out.print(.5 - AG );
      System.out.println(" more American Government credits");
      
      System.out.print("You need ");
      System.out.print(1 - Arts );
      System.out.println(" more Fine/Pratical Arts credits");
      
      System.out.print("You need ");
      System.out.print(.5 - LMS );
      System.out.println(" more Life Management Skills credits");
      
      System.out.print("You need ");
      System.out.print(.5 - PF );
      System.out.println(" more Physical Fitness credits");
      
      System.out.print("You need ");
      System.out.print(.5 - PE );
      System.out.println(" more Pyhiscal Education credits");
      
      System.out.print("You need ");
      System.out.print(8.5 - Electives );
      System.out.println(" more elective credits");
      
      System.out.print("You need ");
      System.out.print(24 - creditsn );
      System.out.println(" more total credits");
   }
}

Here is my code so far for my applet version.

Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import javax.swing.*;

class gui extends JApplet {
    JTextField textfield_1;
    Choice choice_1;
    Choice choice_2;
    Choice choice_3;
    Choice choice_4;
    Choice choice_5;
    Choice choice_6;
    Choice choice_7;
    Choice choice_8;
    Choice choice_9;
    Choice choice_10;
    Choice choice_11;
    Choice choice_12;
    TextField textfield_2;
    TextField textfield_3;
    TextField textfield_4;
    TextField textfield_5;
    TextField textfield_6;
    TextField textfield_7;
    TextField textfield_8;
    TextField textfield_9;
    TextField textfield_10;
    TextField textfield_11;
    TextField textfield_12;
    TextField textfield_13;

    public void init() {
        guiLayout customLayout = new guiLayout();

        getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
        getContentPane().setLayout(customLayout);

        textfield_1 = new JTextField("This program will tell you how many credits you need to graduate");
        getContentPane().add(textfield_1);

        choice_1 = new Choice();
        choice_1.addItem("0");
        choice_1.addItem("0.5");
        choice_1.addItem("1");
        choice_1.addItem("1.5");
        choice_1.addItem("2");
        choice_1.addItem("2.5");
        choice_1.addItem("3");
        choice_1.addItem("3.5");
        choice_1.addItem("4");
        getContentPane().add(choice_1);

        choice_2 = new Choice();
        choice_2.addItem("0");
        choice_2.addItem("0.5");
        choice_2.addItem("1");
        choice_2.addItem("1.5");
        choice_2.addItem("2");
        choice_2.addItem("2.5");
        choice_2.addItem("3");
        getContentPane().add(choice_2);

        choice_3 = new Choice();
        choice_3.addItem("0");
        choice_3.addItem("0.5");
        choice_3.addItem("1");
        choice_3.addItem("1.5");
        choice_3.addItem("2");
        choice_3.addItem("2.5");
        choice_3.addItem("3");
        getContentPane().add(choice_3);

        choice_4 = new Choice();
        choice_4.addItem("0");
        choice_4.addItem("0.5");
        choice_4.addItem("1");
        getContentPane().add(choice_4);

        choice_5 = new Choice();
        choice_5.addItem("0");
        choice_5.addItem("0.5");
        choice_5.addItem("1");
        getContentPane().add(choice_5);

        choice_6 = new Choice();
        choice_6.addItem("0");
        choice_6.addItem("0.5");
        getContentPane().add(choice_6);

        choice_7 = new Choice();
        choice_7.addItem("0");
        choice_7.addItem("0.5");
        getContentPane().add(choice_7);

        choice_8 = new Choice();
        choice_8.addItem("0");
        choice_8.addItem("0.5");
        choice_8.addItem("1");
        getContentPane().add(choice_8);

        choice_9 = new Choice();
        choice_9.addItem("0");
        choice_9.addItem(".5");
        getContentPane().add(choice_9);

        choice_10 = new Choice();
        choice_10.addItem("0");
        choice_10.addItem("0.5");
        getContentPane().add(choice_10);

        choice_11 = new Choice();
        choice_11.addItem("0");
        choice_11.addItem("0.5");
        getContentPane().add(choice_11);

        choice_12 = new Choice();
        choice_12.addItem("0");
        choice_12.addItem("0.5");
        choice_12.addItem("1");
        choice_12.addItem("1.5");
        choice_12.addItem("2");
        choice_12.addItem("2.5");
        choice_12.addItem("3");
        choice_12.addItem("3.5");
        choice_12.addItem("4");
        choice_12.addItem("4.5");
        choice_12.addItem("5");
        choice_12.addItem("5.5");
        choice_12.addItem("6");
        choice_12.addItem("6.5");
        choice_12.addItem("7");
        choice_12.addItem("7.5");
        choice_12.addItem("8");
        choice_12.addItem("8.5");
        getContentPane().add(choice_12);

        textfield_2 = new TextField("language Arts Credits");
        getContentPane().add(textfield_2);

        textfield_3 = new TextField("Mathematics credits");
        getContentPane().add(textfield_3);

        textfield_4 = new TextField("Science credits");
        getContentPane().add(textfield_4);

        textfield_5 = new TextField("World History credits");
        getContentPane().add(textfield_5);

        textfield_6 = new TextField("American History credits");
        getContentPane().add(textfield_6);

        textfield_7 = new TextField("Econimic credits");
        getContentPane().add(textfield_7);

        textfield_8 = new TextField("American Goverment credits");
        getContentPane().add(textfield_8);

        textfield_9 = new TextField("Practical/Fine Art credits");
        getContentPane().add(textfield_9);

        textfield_10 = new TextField("Life Management Skill credits");
        getContentPane().add(textfield_10);

        textfield_11 = new TextField("Personal Fitness credits");
        getContentPane().add(textfield_11);

        textfield_12 = new TextField("Personal Education credits");
        getContentPane().add(textfield_12);

        textfield_13 = new TextField("Elective credits");
        getContentPane().add(textfield_13);

        setSize(getPreferredSize());

    }

    public static void main(String args[]) {
        gui applet = new gui();
        JFrame window = new JFrame("gui");

        window.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        applet.init();
        window.getContentPane().add("Center", applet);
        window.pack();
        window.setVisible(true);
    }
}

class guiLayout implements LayoutManager {

    public guiLayout() {
    }

    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+216,insets.top+8,408,32);}
        c = parent.getComponent(1);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+136,72,24);}
        c = parent.getComponent(2);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+168,72,24);}
        c = parent.getComponent(3);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+200,72,24);}
        c = parent.getComponent(4);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+232,72,24);}
        c = parent.getComponent(5);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+264,72,24);}
        c = parent.getComponent(6);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+296,72,24);}
        c = parent.getComponent(7);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+328,72,24);}
        c = parent.getComponent(8);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+360,72,24);}
        c = parent.getComponent(9);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+392,72,24);}
        c = parent.getComponent(10);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+424,72,24);}
        c = parent.getComponent(11);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+456,72,24);}
        c = parent.getComponent(12);
        if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+488,72,24);}
        c = parent.getComponent(13);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+136,144,24);}
        c = parent.getComponent(14);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+168,144,24);}
        c = parent.getComponent(15);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+200,144,24);}
        c = parent.getComponent(16);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+232,144,24);}
        c = parent.getComponent(17);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+264,144,24);}
        c = parent.getComponent(18);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+296,144,24);}
        c = parent.getComponent(19);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+328,144,24);}
        c = parent.getComponent(20);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+360,144,24);}
        c = parent.getComponent(21);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+392,144,24);}
        c = parent.getComponent(22);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+424,144,24);}
        c = parent.getComponent(23);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+456,144,24);}
        c = parent.getComponent(24);
        if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+488,144,24);}
    }
}
 
my god you have a lot of redundant programming... run loops dude.

As for taking what the user selects i really cannot say. If it works the same as C#(which is almost identical except for some syntax) then you just need to say something like

string variable = user_select.text()

then run your stuff you need and spit out the answer... im not sure i would need to look over your code more but im at work and i don't have visual studio here... haha
 
boris_37 said:
my god you have a lot of redundant programming... run loops dude.

As for taking what the user selects i really cannot say. If it works the same as C#(which is almost identical except for some syntax) then you just need to say something like

string variable = user_select.text()

then run your stuff you need and spit out the answer... im not sure i would need to look over your code more but im at work and i don't have visual studio here... haha

I'll tidy it up with loops and all after I get it working.

Code:
string variable = user_select.text()
That seems right but I can't seem to get that to work, but maybe I'm just doing 1 step wrong. Just mess one thing up, that's all it takes.

Why can't it be as easy as writting the comand line version?

Oh and thanks for the fast response.
 
personally i found gui a lot more functional. I'm not sure why it isn't working as i have not taken java and do not actually have the time to look at your code right now.

Command line rocked the casbah though. Me and my friend made a ASCII text based adventure in command line, it was amazing except i missed 1 part of code so you couldn't exit one room. Otherwise it ran great and was a good 5-10 minute game.
 
boris_37 said:
personally i found gui a lot more functional. I'm not sure why it isn't working as i have not taken java and do not actually have the time to look at your code right now.

Command line rocked the casbah though. Me and my friend made a ASCII text based adventure in command line, it was amazing except i missed 1 part of code so you couldn't exit one room. Otherwise it ran great and was a good 5-10 minute game.

Oh yeah I came here hoping someone might say, yeah I know what happened, you just missed this.... I've updated my coding and added comments in there:

http://24.110.34.82/GUI2.java.txt

I am not all sure what I'm doing with the gui, after all this is my first gui/applet and I'm trying to write it with out really know java, beyond what I've done with my command line.
 
yeah i can't say.... except my god put some for loops in there. You will cut your program in at least half.. maybe even 3/4 then you will at least be able to figure out what you're doing wrong instead of looking over 100 lines of code...
 
I'll put loops in when I learn how. I do not remember the Java 2 for Dummies tell how to do loops. I'm going to check that out from the library again this week.
 
So I've worked on it more now, and 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 textField. Here is my whole code.

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.

Code:
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


Code:
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
 
Captain Newbie said:
A large distinction is drawn between Double (object) and double (primitive), in spite of the only thing different is capitalization.

I believe to convert int -> String it's String.valueOf(int arg0).
It's actually:
Integer.toString(int i)
 
wait I am confused.

I want a integer to show up there.


Oh I think I get what you guys are saying. I have to take the integer value "LAC" and convert it to a string value?

See my final idea is to have it be were in the label it prints another variable called LAN, that I get from saying "LAN = 4 - LAC".

Alright I am going to go try it now.

edit:

Code:
        choice_LA1 = new TextField("0");							//First textField on the left
        add(choice_LA1);
        double LAC = Double.parseDouble(choice_LA1.getText());  //how I am getting the user entered integer and making it a varible
			LAN = 4 - LAC;
			Double.toString(double LAC);        //line 69, aka error line

Yes I changed everything to double, becuase I remembered that latter on I am going to get some decimal numbers. So I changed it to that, and now I get 2 other erros, " '.class' expected" and " ')' expected" both online 69
 
Trombe said:
Code:
Double.toString(double LAC);        //line 69, aka error line

Should be:
Double.toString(LAC);

Thank you, that fixed the error.

Now my problem seems to be that is is not taking the value the user entered. I can't get it to give me the value, it just has 0.0, and does not change when I enter a number.
 
Trombe said:
Do you know what an action listener is?

*pulls out Java for Dummies*

Yes I have it right here in my book :).

I need a document listener don't I. The book gave me the impression that the "Textfield.getText()" could be used to grab the value.

So I need to add "void changeupdate(Document e)"? Err I'm not sure?

Edit:

I've completely redone my GUI to be completely in Swing, and no more of the old AWT. I still am not sure how to add an ActionListener. I tried and here was my results

Code:
 LA_Credits = new JTextField("0"); 
        getContentPane().add(LA_Credits);
   LA_Credits.addActionListener(this);
   double LAC = Double.parseDouble(LA_Credits.getText());

That is just the first TextField. I thought I had everything right but I get the error "addActionListener(java.awt.event.ActionListener) in javax.swing.JTextField cannot be applied to (creditsGUI)"
 
Last edited:
Back