Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: General assistance for newbie

  1. #1
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default General assistance for newbie

    Hello, I am not a newbie in the sense that I just started but it has been a while since I have done any programming. I am making a "Savings account" program and I am having trouble with the GUI. What am I doing wrong? What should I do to fix it?
    Here is my code
    import java.awt.*; 
    import javax.swing.*;
    import java.awt.event.*;
     
    class SavingsGUI extends JFrame implements ActionListener{
      JButton deposit;
      JButton withdraw;
      JButton money;
      JButton num1;
      JButton num2;
      JButton num3;
      JButton num4;
      JButton num5;
      JButton num6;
      JButton num7;
      JButton num8;
      JButton num9;
      JButton num0;
      JButton num50;
      JButton num100;
      double balance = 0.0; 
      // constructor for ButtonFrame
      SavingsGUI(String title) {
        super(title);
        setLayout(new FlowLayout());
        deposit = new JButton("Deposit");
        add(deposit);
    	withdraw = new JButton("Withdraw");
    	add(withdraw);
    	money = new JButton("Balance");
    	add(money);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
    	deposit.addActionListener(this);
    	withdraw.addActionListener(this);
    	money.addActionListener(this);
    	withdraw.setActionCommand("w");
    	money.setActionCommand("b");
    	deposit.setActionCommand("d");
      }
    	public void actionPerformed(ActionEvent evt) {
    		if (evt.getActionCommand().equals("d")) {
    			//code for depositing
    			JFrame dep = new JFrame("Deposit Amount");
    			setLayout(new FlowLayout());
    			num0 = new JButton("0");
    			num1 = new JButton("1");
    			num2 = new JButton("2");
    			num3 = new JButton("3");
    			num4 = new JButton("4");
    			num5 = new JButton("5");
    			num6 = new JButton("6");
    			num7 = new JButton("7");
    			num8 = new JButton("8");
    			num9 = new JButton("9");
    			num50 = new JButton("$50");
    			num100 = new JButton("$100");
    			dep.add(num7);
    			dep.add(num8);
    			dep.add(num9);
    			dep.add(num4);
    			dep.add(num5);
    			dep.add(num6);
    			dep.add(num1);
    			dep.add(num2);
    			dep.add(num3);
    			dep.add(num50);
    			dep.add(num0);
    			dep.add(num100);
    			dep.pack();
    			dep.setVisible(true);
    			dep.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    			System.out.println("Deposit works");
    		}
    		if (evt.getActionCommand().equals("w")) {
    			//code for withdrawing
    			System.out.println("Withdraw works");
    		}	
    		if (evt.getActionCommand().equals("b"))	{	
    			//code for displaying balance
    			System.out.println("Total amount of money is: $" + balance);
    		}
    	}
    }
     
    public class test {
      public static void main (String[] args) {
        SavingsGUI frm = new SavingsGUI("Savings Account");
        frm.setSize(300, 100);
        frm.setVisible(true);
      }
    }

    Here is a rough sketch of what I want it to look like. Colors do not matter very much.
    Savings.jpg
    Thank you for your help.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    What am I doing wrong?
    Please explain what is wrong.

    Take a look at the tutorial about how to use layout managers:
    http://docs.oracle.com/javase/tutori...out/index.html
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    Sorry. When I run it, nothing shows up but the println to the terminal. The gui part does not appear.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    Where is the constructor for the class?
    Where is the method: gui() called? Did you mean for the gui() method to be coded as a constructor?

    Why are there two JFrames? One is extended the other is created in the gui() method.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    I thought GUI gooey = new GUI(); was the constructor.
    when I try to call that method, an error is returned. something about it cannot be called in a static situation because it is not static.

    I thought I had to construct one...

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    GUI gooey = new GUI();
    That is a call to the class's constructor. See the tutorial on how to write class constructors:
    Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    Rewrite. Now, the frame that appears when the deposit button is clicked just shows one button when it should show 12.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    just shows one button
    Which button is shown? The first one added or the last one?

    What layout manager is controlling the layout for the container that the buttons are being added to?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    The last one. I used FlowLayout()

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    Where is it set for the dep JFrame?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    dep.setLayout....
    *facepalm*
    now the buttons are all in a line. I would like to see them in a grid format 3(columns)x4(rows). How do I make this happen? Is it a different layout?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    Yes, there are many different layout managers.
    Did you look at the link in post#2?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    nvm. I googled different layoutmanagers and found gridlayout.

    --- Update ---

    I want to put a JTextField above the buttons in dep and wit that displays the amount. When a button is pressed, it should concatenate to the end of the present amount of $0.00. When I add it to the already present window, it messes up the buttons. I want the textfield to stretch across the top row and have the buttons under it. How do I resolve this?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    Use different layout managers and JPanels that hold some of the components with its own layout manager.
    With a borderlayout put a large component in North and a JPanel with a gridlayout in center that holds the buttons.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    I have the borderlayout set up but I am back to only one button showing. Nothing else. It is the last button added to dep that is showing.
    JFrame dep = new JFrame("Deposit Amount");
    			JTextField depAmt = new JTextField("$***0.00", 3);
    			dep.add(depAmt, BorderLayout.NORTH);
    			dep.setLayout(new BorderLayout());
    			num7 = new JButton("7");
    			dep.add(num7, BorderLayout.CENTER);
    			num8 = new JButton("8");
    			dep.add(num8);
    			num9 = new JButton("9");
    			dep.add(num9);
    			num4 = new JButton("4");
    			dep.add(num4);
    			num5 = new JButton("5");
    			dep.add(num5);
    			num6 = new JButton("6");
    			dep.add(num6);
    			num1 = new JButton("1");
    			dep.add(num1);
    			num2 = new JButton("2");
    			dep.add(num2);
    			num3 = new JButton("3");
    			dep.add(num3);
    			num50 = new JButton("$50");
    			dep.add(num50);
    			num0 = new JButton("0");
    			dep.add(num0);
    			num100 = new JButton("$100");
    			dep.add(num100);
    			dep.pack();
    			dep.setLocationRelativeTo(null);
    			dep.setVisible(true);
    			dep.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    Where is the JPanel with the gridlayout that is supposed to hold the buttons?
    That when filled is added to the center of the borderlayout
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: adding a window to a container
    at java.awt.Container.checkNotAWindow(Container.java: 439)
    at java.awt.Container.addImpl(Container.java:1035)
    at java.awt.Container.add(Container.java:955)
    at javax.swing.JFrame.addImpl(JFrame.java:556)
    at java.awt.Container.add(Container.java:923)
    at SavingsGUI.actionPerformed(Savings.java:76)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2012)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2335)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:404)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.jav a:6288)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:605 3)
    at java.awt.Container.processEvent(Container.java:204 5)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4649)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2103)
    at java.awt.Component.dispatchEvent(Component.java:44 75)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4633)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4297)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4227)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2089)
    at java.awt.Window.dispatchEventImpl(Window.java:2587 )
    at java.awt.Component.dispatchEvent(Component.java:44 75)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:675)
    at java.awt.EventQueue.access$300(EventQueue.java:96)
    at java.awt.EventQueue$2.run(EventQueue.java:634)
    at java.awt.EventQueue$2.run(EventQueue.java:632)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:105)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:116)
    at java.awt.EventQueue$3.run(EventQueue.java:648)
    at java.awt.EventQueue$3.run(EventQueue.java:646)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:105)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 645)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:138)
    That is the error I get when I do
    JFrame btn = new JFrame();
    btn.setLayout(new GridLayout(4,3,10,10));
    dep.add(btn, BorderLayout.CENTER);

    --- Update ---

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: adding a window to a container
    at java.awt.Container.checkNotAWindow(Container.java: 439)
    at java.awt.Container.addImpl(Container.java:1035)
    at java.awt.Container.add(Container.java:955)
    at javax.swing.JFrame.addImpl(JFrame.java:556)
    at java.awt.Container.add(Container.java:923)
    at SavingsGUI.actionPerformed(Savings.java:76)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2012)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2335)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:404)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.jav a:6288)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:605 3)
    at java.awt.Container.processEvent(Container.java:204 5)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4649)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2103)
    at java.awt.Component.dispatchEvent(Component.java:44 75)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4633)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4297)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4227)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2089)
    at java.awt.Window.dispatchEventImpl(Window.java:2587 )
    at java.awt.Component.dispatchEvent(Component.java:44 75)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:675)
    at java.awt.EventQueue.access$300(EventQueue.java:96)
    at java.awt.EventQueue$2.run(EventQueue.java:634)
    at java.awt.EventQueue$2.run(EventQueue.java:632)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:105)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:116)
    at java.awt.EventQueue$3.run(EventQueue.java:648)
    at java.awt.EventQueue$3.run(EventQueue.java:646)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:105)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 645)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:138)
    That is the error I get when I do
    JFrame btn = new JFrame();
    btn.setLayout(new GridLayout(4,3,10,10));
    dep.add(btn, BorderLayout.CENTER);

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    java.lang.IllegalArgumentException: adding a window to a container
    It is not allowed to add a window to a container.
    It is allowed to add just about any other component to a container.

    Use a JPanel NOT a JFrame.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    JFrame dep = new JFrame("Deposit Amount");
    			JPanel btn = new JPanel();
    			btn.setVisible(true);
    			btn.setLayout(new GridLayout(4,3,10,10));
    			JTextField depAmt = new JTextField("$***0.00", 3);
    			dep.setLayout(new BorderLayout());
    			dep.add(depAmt, BorderLayout.NORTH);
    			num7 = new JButton("7");
    			btn.add(num7);
    			num8 = new JButton("8");
    			btn.add(num8);
    			num9 = new JButton("9");
    			btn.add(num9);
    			num4 = new JButton("4");
    			btn.add(num4);
    			num5 = new JButton("5");
    			btn.add(num5);
    			num6 = new JButton("6");
    			btn.add(num6);
    			num1 = new JButton("1");
    			btn.add(num1);
    			num2 = new JButton("2");
    			btn.add(num2);
    			num3 = new JButton("3");
    			btn.add(num3);
    			num50 = new JButton("$50");
    			btn.add(num50);
    			num0 = new JButton("0");
    			btn.add(num0);
    			num100 = new JButton("$100");
    			btn.add(num100);
    			dep.add(btn, BorderLayout.CENTER);
    			dep.setLocationRelativeTo(null);
    			dep.setVisible(true);
    			dep.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    The new window does not open anymore.
    Forgot to setSize. The window was opening really small.

    --- Update ---

    Now that everything is laid out how I want it, it is time to work on getting buttons functioning.
    Here is the code that I'm at right now:
    import java.awt.*; 
    import javax.swing.*;
    import java.awt.event.*;
     
    class SavingsGUI extends JFrame implements ActionListener{
      JButton deposit;
      JButton withdraw;
      JButton money;
      JButton num1;
      JButton num2;
      JButton num3;
      JButton num4;
      JButton num5;
      JButton num6;
      JButton num7;
      JButton num8;
      JButton num9;
      JButton num0;
      JButton num50;
      JButton num100;
      JButton done;
      JButton cancel;
      JButton blank;
      JLabel lbl;
      double balance = 0.0; 
      // constructor for ButtonFrame
      SavingsGUI(String title) {
        super(title);
        setLayout(new FlowLayout());
        deposit = new JButton("Deposit");
        add(deposit);
    	withdraw = new JButton("Withdraw");
    	add(withdraw);
    	money = new JButton("Balance");
    	add(money);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
    	deposit.addActionListener(this);
    	withdraw.addActionListener(this);
    	money.addActionListener(this);
    	withdraw.setActionCommand("w");
    	money.setActionCommand("b");
    	deposit.setActionCommand("d");
    	setLocationRelativeTo(null);
      }
    	public void actionPerformed(ActionEvent evt) {
    		JPanel btn = new JPanel();
    		btn.setVisible(true);
    		btn.setLayout(new GridLayout(5,3,10,10));
    		num7 = new JButton("7");
    		btn.add(num7);
    		num8 = new JButton("8");
    		btn.add(num8);
    		num9 = new JButton("9");
    		btn.add(num9);
    		num4 = new JButton("4");
    		btn.add(num4);
    		num5 = new JButton("5");
    		btn.add(num5);
    		num6 = new JButton("6");
    		btn.add(num6);
    		num1 = new JButton("1");
    		btn.add(num1);
    		num2 = new JButton("2");
    		btn.add(num2);
    		num3 = new JButton("3");
    		btn.add(num3);
    		num50 = new JButton("$50");
    		btn.add(num50);
    		num0 = new JButton("0");
    		btn.add(num0);
    		num100 = new JButton("$100");
    		btn.add(num100);
    		done = new JButton("Done");
    		btn.add(done);
    		blank = new JButton();
    		btn.add(blank);
    		cancel = new JButton("Cancel");
    		btn.add(cancel);
    		if (evt.getActionCommand().equals("d")) {
    			//code for depositing
    			JFrame dep = new JFrame("Deposit Amount");
    			JTextField depAmt = new JTextField("$***0.00", 3);
    			dep.setLayout(new BorderLayout());
    			dep.add(depAmt, BorderLayout.NORTH);
    			dep.add(btn, BorderLayout.CENTER);
    			dep.setLocationRelativeTo(null);
    			dep.setVisible(true);
    			dep.setSize(300,300);
    			dep.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    			System.out.println("Deposit works");
    		}
    		if (evt.getActionCommand().equals("w")) {
    			//code for withdrawing
    			JFrame wit = new JFrame("Withdrawal Amount");
    			JTextField witAmt = new JTextField("$***0.00", 3);
    			wit.setLayout(new BorderLayout());
    			wit.add(witAmt, BorderLayout.NORTH);
    			wit.add(btn, BorderLayout.CENTER);
    			wit.setLocationRelativeTo(null);
    			wit.setVisible(true);
    			wit.setSize(300,300);
    			wit.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    			System.out.println("Withdraw works");
    		}	
    		if (evt.getActionCommand().equals("b"))	{	
    			//code for displaying balance
    			JFrame bal = new JFrame("Balance Amount");
    			lbl = new JLabel("Total Balance is: $" + balance, JLabel.CENTER);
    			lbl.setFont(new Font("Serif",Font.PLAIN, 37));
    			bal.add(lbl);
    			bal.setVisible(true);
    			bal.setSize(600,100);
    			bal.setLocationRelativeTo(null);
    			bal.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    			System.out.println("Balance works");
    		}
    	}
    }
     
    public class Savings {
      public static void main (String[] args) {
        SavingsGUI frm = new SavingsGUI("Savings Account");
        frm.setSize(300, 75);
        frm.setVisible(true);
      }
    }
    I want to make it where when a button is pressed, its value is added to the rightmost place in the JTextField and as more buttons are pressed they each push what is already there over one place. When Done is pressed, whatever is in the JTextField should be added to balance.
    First question: How do I make the value in the JTextView into a variable that I can use?
    Second: How do I get the buttons to put their value in the JTV in the manner I want?

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    What is a JTextView?

    How do I get the buttons to put their value in the JTV in the manner I want?
    If its a class, read its API doc to see what methods it has that will do what you want.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    See above post. Everything is laid out how I like it but the buttons don't do anything yet. I am eternally grateful to you for your kind service. Thank you for helping!

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    but the buttons don't do anything yet.
    They need action listeners added to them so something can be done when they are pressed.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    action listeners set. where do I put the commands for what they need to do?

  24. #24
    Member
    Join Date
    Jan 2013
    Location
    Central Texas
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: General assistance for newbie

    Amt is defined in the SavingsGUI method of class SavingsGUI.

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: General assistance for newbie

    If you want other methods to have access to it, it needs to be defined at the class level (outside of a method).
    If you don't understand my answer, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. [SOLVED] Homework assistance
    By hhman1 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 29th, 2013, 06:16 PM
  2. [SOLVED] for loop assistance
    By Kseidel in forum Loops & Control Statements
    Replies: 3
    Last Post: September 17th, 2012, 08:10 PM
  3. Need some assistance please
    By JavaPhish in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2012, 10:00 AM
  4. New to the complmunity, need some assistance please.
    By nakedtriple in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 7th, 2011, 06:14 AM
  5. Newbie: general question on trying to get a simple Pokemon game to work
    By willmer in forum Object Oriented Programming
    Replies: 7
    Last Post: July 13th, 2011, 07:33 AM