Hi all, I'm taking an introductory class into programming and often I can't get help and don't have a lot of time to check around for answers, so I'm turning to this awesome place. I hope to post code issues and code requests here and get help. I am quite new to Java to please be basic, for now. If it help, II understand TI basic so you can explain it in that sense.

No issues now.

Code:


/**
 * Program displays a GUI window with the number 5 preselected. Users imput #, the programs responds, high, low, or exact depending on the guess.
 *
 * @Josh Pham
 * @1.0
 */

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Guess_the_Number implements ActionListener
{
    JPanel Main;
    JFrame Frame;
    Container Container;
    JTextField Guess;
    String GuessString;
    JButton Run;
    JLabel Instructions,Hint;
    int Answer,GuessInt;
    public Guess_the_Number()
    {
        Frame = new JFrame("Guess the Number");
        Frame.setBounds(200,300,300,200);
        Container = Frame.getContentPane();
        Main = new JPanel();
        Instructions = new JLabel("Enter a # between 1-10");
        Hint = new JLabel("");
        Run = new JButton("This is my guess");
        Run.addActionListener(this);
        Answer = 5;                                       //This is not the Answer, don't try it!!
        Guess = new JTextField(3);
        Container.add(Main);
        Main.add(Instructions);
        Main.add(Guess);
        Main.add(Run);
        Main.add(Hint);
       
        Frame.show();
    }
    public void actionPerformed(ActionEvent event)
    {
        if((event.getSource() == Run))
        {
            GuessString = Guess.getText();
            GuessInt = Integer.parseInt(GuessString);
            if(GuessInt == Answer)
            {
                Hint.setText("Cheater. You know the answer!");
                Hint.setForeground(new Color(0,120,0));
            }
            if(GuessInt > Answer)
            {
                Hint.setText("                  Failure; Too high!                  ");
                Hint.setForeground(new Color(120,0,0));
            }
            if(GuessInt < Answer)
            {
                Hint.setText("                  Failure; Too low!                  ");
                Hint.setForeground(new Color(0,0,120));
            }
        }
    }
}
JPfowl wrote:
often I can't get help and don't have a lot of time to check around for answers


My time is infinitely more valuable than your time, so I probably won't help you at all since you are unwilling to help yourself.

Asking questions if you are genuinely stuck *AND HAVE SEARCHED AROUND* is fine. Asking questions because you are too lazy to search yourself is being a douchebag.

Quote:
No issues now.


Then don't start a fucking thread.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement