Make A Program Which Has Four Different Buttons, Which Do Different Things?

So far here is what I have, I need program in which number starts at thirteen then one will take the current number and cut in half, other will multiply it by 3 and add 1, and other will make current number a random value from one to a hundred. The Quit one will just exit the program. Heres what i have so far:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Lab05 extends JFrame
private Container content;          //fields
private LayoutManager layout;
private JLabel label;
private JButton button1, button2, button3, quit;
private ActionListener listener1, listener2, listener3, quitter;
private int number,n;
public Lab05()          //default-constructor
formatWindow();
label = createAndAddLabel("Current Number: 13");
button1 = createAndAddButton("DIV 2",listener1);
button2 = createAndAddButton("TIMES 3 PLUS 1",listener2);
button3 = createAndAddButton("Random.",listener3);
quit = createAndAddButton("Quit.",quitter);
listener1 = new Handler1();
listener2 = new Handler2();
listener3 = new Handler3();
quitter = new Quitter();
public void formatWindow()
content = getContentPane();
layout = new FlowLayout();
content.setLayout(layout);
private JLabel createAndAddLabel(String s)
JLabel temp = new JLabel();
temp.setText(s);
content.add(temp);
return temp;
     //use this method for creating and adding various different buttons
private JButton createAndAddButton(String s, ActionListener li)
JButton temp = new JButton();
temp.setText(s);
temp.addActionListener(li);
content.add(temp);
return temp;
     //use this method for controlling the affect of pressing different buttons
private void process(int x)
number = x;
private class Handler1 implements ActionListener
public void actionPerformed(ActionEvent e)
private class Handler2 implements ActionListener
public void actionPerformed(ActionEvent e)
private class Handler3 implements ActionListener
public void actionPerformed(ActionEvent e)
private class Quitter implements ActionListener
public void actionPerformed(ActionEvent e)
System.exit(0);
public static void main(String[] args)
     //create graphics window
Lab05 window = new Lab05();
     //configure graphics window
window.setSize(175, 175);
window.setLocation(300, 175);
window.setTitle("Unit3, Lab05: Hailstone");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     //display graphics window
window.setVisible(true);
}

4. please don't use abbreviations such as "ur" for"your" :)
Please don't say anything that offends smckee6452. He
can get kinda grumpy when someone does that. ;-)
Gotcha!:) actually, i'm not offended at all when people do stuff like that. there are multiple reasons i believe you shouldn't condense to "internet words":
1. because some people on the forums know only broken english and when you throw unknown abbreviations at them they have no idea what you're ("u r") talking about. and some people use tools such as "babel fish" to translate to different languages (although, i'm not sure how accurate that would be).
2. even though it is faster to type "ur" and "u" and "2" and "ne way" and etc., it is slower to read them because the human brain has been conditioned to look at "your" and "you" and "to" and "anyway" and skip over them quickly absorbing the meaning and syntax all in one fell swoop. you'll find yourself having to sound out things like "neway" for your brain to snag the meaning...
but, alas, james is correct. i am easily annoyed.
that is all. ;)

Similar Messages

  • TS1717 This article is vague and unhelpful. My iTunes needs help from a pro. I have over 120,000 songs -- NO movies, TV, radio, or books... I have other programs which efficiently run things which are not audio-based. So why can I not get iTunes working w

    This article is vague and unhelpful. My iTunes needs help from a pro.
    I have over 120,000 songs -- NO movies, TV, radio, or books...
    I have other programs which efficiently run things which are not audio-based.
    So why can I not get iTunes working well?? It now takes at least 10 secs for any operation to be completed!
    That is just plain evil. But I am sure I could do something to help.
    All the music is on an 2T external drive.

    TS1717 as noted in the thread title...
    Brigancook, is the library database on the external or just the media? iTunes reevaluates smart playlists and rewrites its database after every action on the library. I've found this can make a library half that size, with a lot of smart playlists, quite sluggish. That said I'm aware part of my problem is aging hardware. Having the database on the internal drive may improve performance if it is currently on the external.
    I'd expect to see an exponential relationship between size and response time which may explain what you see. Cutting down on the number of smart playlists might help. If we're really lucky the long awaited iTunes 11 might have streamlined some of the background processes as well as cleaning up the front end.
    tt2

  • How To Make A Program Which When I Press A Button The Number Goes Up One?

    I have already made this:
    import java.awt.Container;
    import java.awt.LayoutManager;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    public class Lab04 extends JFrame
    private Container content;
    private LayoutManager layout;
    private JLabel number, division, modulus, space;
    private JTextField text;
    private String string;
    private ActionListener listener;
    private char char1;
    private int x, Add1, Add2;
    private JButton bAdd;
    public Lab04()
    formatWindow();
    listener = new Handler();
    bAdd = createAndAddButton("+1");
    number = createAndAddLabel("Current Number: 0");
    division = createAndAddLabel(" n DIV 4 = 0");
    space = createAndAddLabel(" ");
    modulus = createAndAddLabel(" n MOD 4 = 0");
    public void formatWindow()
    content = getContentPane();
    layout = new FlowLayout();
    content.setLayout(layout);
    private JLabel createAndAddLabel(String s)
    JLabel temp = new JLabel();
    temp.setText(s);
    content.add(temp);
    return temp;
    private JTextField createAndAddTextField(int x)
    JTextField temp = new JTextField(x);
    temp.addActionListener(listener);
    content.add(temp);
    return temp;
    private JButton createAndAddButton(String s)
    JButton temp = new JButton();
    temp.setText(s);
    temp.addActionListener(listener);
    content.add(temp);
    return temp;
    private void process()
    int x = 0;
    Add1 = x +1;
    private void output()
    number.setText("Current Number: "+x+1);
    private class Handler implements ActionListener
    public void actionPerformed(ActionEvent e)
    process();
    output();
    public static void main(String[] args)
    //create graphics window
    Lab04 window = new Lab04();
    //configure graphics window
    window.setSize(200, 150);
    window.setLocation(300, 175);
    window.setTitle("Unit 3 Lab03: Filling Out Forms");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //display graphics window
    window.setVisible(true);
    And all it does is it gives me the number 01, what should I do?

    public void process{
    int x = 0;
    Add1 = x +1;
    }just what is this supposed to do? every time you call it, it create a primitive x with value 0, and then makes Add1 equal to x+1. that will be 1 no matter how many times you call it.

  • Adobe Cloud has 2 different Muse programs.... how do I know which one is the newer better version?

    So I am new to Muse, and my Adobe Cloud has 2 different programs from Muse... how do I know which one is the newer better version?
    One Must program (Muse CC 2014.2)  has a black background when working on it... it looks like other Adobe programs such as Photoshop.
    The other one is light color (Muse CC) very similar to the black color Muse on functions.....
    One of the difference I notice is that the light color Muse has a few widgets in the library, while the black background Muse seems to have an empty library
    So... why are there 2 different Muse programs in my Adobe Cloud?

    Hi
    The latest version of Muse is 2014.2, so you need to uninstall another version of Muse manually.
    regarding the items in Library, you can add items in your library manually, as shown in this article
    Adobe Muse Help | Organizing and reusing design elements using Library panel
    Please let me know if you have any other query.

  • How do i make the program hold after it has created a JFrame

    I have created a JFrame with which the user shall login to a server. I call this JFrame from my main method (the JFrame-class is in a separate file). My problem is that after the login-window is created and set visible, my main method continues, i would like it to wait until the user have logged in before running the rest of the code.
    this i my main method:
    new LoginWindow();
    System.out.println("Logged in: "+Session.isLoggedin()+
                    "\nUsername: "+Session.getUsername());Session.isLoggedin() returns a boolean, true if user is logged in and otherwise false. class LoginWindow extends JFrame.
    i have tried to use a while-loop to solve my problem:
    while(!Session.isLoggedin()) { }and also
    whiel(true){
        if(Session.isLoggedin())
            break;
    }these while-loops never breaks, i have waited for about 3 min after successful login.It isn't because Session.isLoggedin() returns false, it does return true after a successful login (i've checked).
    the funny thing however is if i print something in the while-loop i does break when login is finished
    example:
    whiel(true){
        System.out.println(Session.isLoggedin());
        if(Session.isLoggedin())
            break;
    }this code makes the program wait until the login-phase is complete but i don't want it to print "text" a few thousand times while the user is logging in. (i've used "hej" as output aswell)
    Since i have no idea how long it will take for a user to log in i can't use the System.sleep(value) method.
    I would really appreciate any help
    Thanks in advance
    //Oscar

    SnuShogge wrote:
    I am still curious about why the while-loop only breaks if i print something using System.out.println(""), i didn't think that would make a difference since the break-statement remains the same.In general you should avoid trying to use while (true) or its variants in a Swing GUI as it often messes with the EDT, the main thread that renders the GUI graphics and interacts with the user.
    My problem i however partially solved by using a JDialog instead of a JFrame. I am planning on using JFrame later in the program so the problem might come back to haunt me if it isn't solved.This may not be a great idea. Usually an application has one single JFrame. Most other distinct windows a dialogs of one sort or another and should be JDialogs, not JFrames. Often better still is to use a CardLayout to swap JPanels or other components.

  • HT5819 my digital drum kit has four toms. How do i make it work?

    I have a problem. My digital drumkit has four toms but the drumkit designer has only three. How do i make it work?
    My hihat stay open all the time even if i use the pedal.

    Try a system reset.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until the screen blacks out or you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.
    There's more to try but let's go a bit at a time.

  • HI Team, Recently One week back I bought a new iphone 5 from India. They have given me a used mobile which has a different IMEI number when compared to the IMEI number present on the box. Please let me know how to proceed further

    HI Team, Recently One week back I bought a new iphone 5 from India. They have given me a used mobile which has a different IMEI number when compared to the IMEI number present on the box. Please let me know how to proceed further

    When you went back to the place where you purchased this phone, & asked them, what did they say?
    No one here can help you with this, nor can/will Apple. You need to take this up with whoever you purchased this phone from.

  • My iPad has a different Apple ID than the Apple ID on my computer. The iPad Apple ID has an email address that I no longer use. If I try to add the email address that I now use (and which is my Apple ID on the computer), it won't allow me to add it.

    My iPad has a different Apple ID than the Apple ID on my computer. The iPad Apple ID has an email address that I no longer use. If (while on the iPad) I go to My Apple ID and try to change or add the email address that I now use (and which already is my Apple ID on the computer), it won't allow me to add it. It says : "Email address is already verified for another Apple ID"  I haven't really been aware of this as a problem until I tried (for the first time) to sync my iPad to the computer and became aware that certain things wouldn't transfer. What is the solution to this?

    What are you having problems with ?
    This post was about having updated the primary email address on an iTunes account via a computer - if you do that you might need to log out of the account on an iPad by tapping on the id in Settings > iTunes & App Store and then log back in with the updated version of the account for that email address change to be recognised on your iPad. If you don't log out and back in then an iPad (or iPhone or iPod Touch) might continue to show the old version of the iTunes account id.

  • Hi i have the same apple id for my iPad and my mac. my iPhone has a different one. My i cloud on my mac seems to be the iCloud on my iPad, if that makes sense so its not sending my photos from my mac to the cloud. how do i change it to upload mac?

    hi i have the same apple id for my iPad and my mac. my iPhone has a different one. My i cloud on my mac seems to be the iCloud on my iPad, if that makes sense so its not sending my photos from my mac to the cloud. how do i change it to upload mac pictures instead? thanks

    Did you go into Settings > Store and then tap your old ID, sign out and then enter your new ID?

  • The bookmarks toolbar is there but has no item buttons on it. How do I get the items back for this toolbar? Also would like to know if the toolbars can be put on the same line to make more room on the page (drag & drop) ??

    The bookmarks toolbar is there but has no item buttons on it. How do I get the items back for this toolbar?
    Also would like to know if the toolbar can be put on the same line to make more room on the page (drag & drop) ?? Like the menu & bookmarks toolbar could/should fit on same line. This would add more page view...
    Floyd Perry
    Thanks

    Check that you still have the "Bookmarks Toolbar items" placed on the Bookmarks Toolbar
    * Make sure that you have the "Bookmarks Toolbar" visible: "View > Toolbars"
    * Check in "View > Toolbars > Customize" that the "Bookmarks Toolbar items" is on the Bookmarks Toolbar
    * If the "Bookmarks Toolbar items" is not on the Bookmarks Toolbar then drag it back from the Customize window onto the Bookmarks Toolbar
    * If you do not see the "Bookmarks Toolbar items" then click the "Restore Default Set" button
    You can only move the content from a toolbar onto other toolbars if all toolbars support that feature. You need to check that in the options of each toolbar.

  • HT204053 I have an iCloud account on my Mac which has a different account name to that on my iPhone. How can I change the Mac account name to that on the iPhone?

    Hi,
    I have an iCloud account on my Mac which has a different account name to the iCloud account on my iPhone. How can I change the Mac account name to match the iPhone one? Kuranda.

    You can't change it in one step. Sign out of the one now on the Mac, sign onto the right one.

  • Need a program which finds out if a user has not logged for 3 days?

    HI,
       I NEED A PROGRAM WHICH FINDS OUT IF ANY USER HAS NOT LOGGED FOR THREE DAYS
        AND SEND A MAIL TO THE BASIS TEAM.IT SHOULD BE SHEDULED AS A BACKGROUND PROCESS.
    I SEARCHED IN GOOGLE BUT NOT ABLE TO FIND IT.
    PLEASE HELP ME OUT WITH THIS.
                    REGARDS,
                          MANI

    use table USR02 and analyse field field TRDAT
    X = sy-datum - usr02-trdat.
    -> if x ge 3...
    for mail use e.g. fm SO_NEW_DOCUMENT_ATT_SEND_API1
    hope that helps
    Andreas from germany

  • I have bought a Macbook Pro Retina, and the iPhoto which comes with it, has a different iPhoto Book menu.  I cannot see how to put text at the bottom of the pages of photographs, instead of the default place in the middle.  Is there a way to do this?

    I have bought a Macbook Pro Retina, and the iPhoto which comes with it, has a different iPhoto Book menu.  I cannot see how to put text at the bottom of the pages of photographs, instead of the default place in the middle.  Is there a way to do this?

    There are different templates for iPhoto books and they differ from version of iPhoto to iPhoto, so explore the other options.

  • How can I import one iweb site from my laptop to my iMac, which already has four sites built on it?

    I created a website on my laptop using iweb, and would like to export the project so I can import it into the iWeb on my iMac, which already has four other sites that I created in it.  I can't seem to find any info or threads on being able to import just one project INTO my iWeb folder when there are already other sites I do not want to lose...anyone know how I can do this?  I can only find info on exporting and importing the entire DOMAIN file...
    Any help much appreciated.

    Use iWebSites to add and merge the domain file(s) :
    http://www.wyodor.net/_Demo/Aptana/iWebSites.html

  • How do I make this program generate a new problem once the button is hit

    Here is the code... appreciate any help given
    How do I make this program generate a new set of problem when the "NEXT" button is clicked and continue until the END button is hit
    package javaapplication3;
    import java.awt.GridLayout;
    import java.awt.Window;
    import javax.swing.*;
    import java.awt.event.*;
    * @author Sylvester Saulabiu
    class Grid extends JFrame{
        final int score = 0;
        final int total = 0;
        Grid(){
            //Set Layout of Flashcard
            setLayout(new GridLayout(4, 4, 2 , 2));
            //Create Panels
            JPanel p2 = new JPanel();
            JPanel p3 = new JPanel();
            final JPanel p1 = new JPanel();
            //Create Radio buttons & group them
            ButtonGroup group = new ButtonGroup();
            final JRadioButton ADD = new JRadioButton("Addition");
            final JRadioButton SUB = new JRadioButton("Subtraction");
            final JRadioButton MUL = new JRadioButton("Multiplication");
            final JRadioButton DIV = new JRadioButton("Division");
            p2.add(ADD);
            p2.add(SUB);
            group.add(ADD);
            group.add(SUB);
            group.add(MUL);
            group.add(DIV);
            p2.add(ADD);
            p2.add(SUB);
            p2.add(DIV);
            p2.add(MUL);
            //Create buttons
            JButton NEXT = new JButton("NEXT");
            JButton END = new JButton("End");
            //Create Labels
            JLabel l1 = new JLabel("First num");
            JLabel l2 = new JLabel("Second num");
            JLabel l3 = new JLabel("Answer:");
            JLabel l4 = new JLabel("Score:");
            final JLabel l5 = new JLabel("");
            JLabel l6 = new JLabel("/");
            final JLabel l7 = new JLabel("");
            //Create Textfields
            final JTextField number = new JTextField(Generator1());
            final JTextField number2 = new JTextField(Generator1());
            final JTextField answer = new JTextField(5);
            //Add to panels
            p1.add(l1);
            p1.add(number);
            p1.add(l2);
            p1.add(number2);
            p1.add(l3);
            p1.add(answer);
            p1.add(l4);
            p1.add(l5);
            p1.add(l6);
            p1.add(l7);
            p3.add(NEXT);
            p3.add(END);
            //Add panels
            add(p2);
            add(p1);
            add(p3);
            //Create Listners
      NEXT.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
             int answer1 = 0;
             //Grab the numbers entered
             int numm1 = Integer.parseInt(number.getText());
             int numm2 = Integer.parseInt(number2.getText());
             int nummsanswer = Integer.parseInt(answer.getText());
             //Set the score and total into new variabls
             int nummscore = score;
             int nummtotal = total;
             //Check if the add radio button is selected if so add
             if (ADD.isSelected() == true){
                 answer1 = numm1 + numm2;
             //otherwise check if the subtract button is selected if so subtract
             else if (SUB.isSelected() == true){
                 answer1 = numm1 - numm2;
             //check if the multiplication button is selected if so multiply
             else if (MUL.isSelected() == true){
                 answer1 = numm1 * numm2;
             //check if the division button is selected if so divide
             else if (DIV.isSelected() == true){
                 answer1 = numm1 / numm2;
             //If the answer user entered is the same with th true answer
             if (nummsanswer == answer1){
                 //add to the total and score
                 nummtotal += 1;
                 nummscore += 1;
                 //Convert the input back to String
                 String newscore = String.valueOf(nummscore);
                 String newtotal = String.valueOf(nummtotal);
                 //Set the text
                 l5.setText(newscore);
                 l7.setText(newtotal);
             //Otherwise just increase the total counter
             else {
                 nummtotal += 1;
                 String newtotal = String.valueOf(nummtotal);
                 l7.setText(newtotal);
      //Create End listener
    END.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // get the root window and call dispose on it
            Window win = SwingUtilities.getWindowAncestor(p1);
            win.dispose();
    String Generator1(){
         int randomnum;
         randomnum = (1 + (int)(Math.random() * 20));
         String randomnumm = String.valueOf(randomnum);
         return randomnumm;
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            JFrame frame = new Grid();
            frame.setTitle("Flashcard Testing");
            frame.setSize(500, 200);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }Edited by: SirSaula on Dec 5, 2009 4:39 PM

    Extract code into methods, so that when an action is performed a method is called. That way you can reuse the method for purposes such as resetting textfields to their default values, scores to default values, etc.
    You can go one step further and seperate the GUI layer from the processing layer, by deriving classes that for example maintain and calculate a score.
    Mel

Maybe you are looking for