6 Replies - 389 Views - Last Post: 29 November 2012 - 08:31 PM Rate Topic: -----

#1 fritozy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-November 12

Giving (static JButton Increase=new JButton) a numerical value?

Posted 29 November 2012 - 06:57 PM

static JButton Increase=new JButton( "-Press To Increase by 100-" ) ;
Is what I would like to give a value and increase the value of another variable but it tells me when I try to add it in to an (If statement) that It will not use a Jbutton with an int value. The graphics for the code are aleready in place, it is fairly extensive and would prefer not to add the whole code. Just would like to know how to make it so that clicking the button increases the value of an int variable by what number I Select.

Im extremely new to this stuff only been two years so explain as simply as humanly possible please.[/b]

This post has been edited by pbl: 29 November 2012 - 07:13 PM
Reason for edit:: Removed completly useless presentation stuff


Is This A Good Question/Topic? 0
  • +

Replies To: Giving (static JButton Increase=new JButton) a numerical value?

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Giving (static JButton Increase=new JButton) a numerical value?

Posted 29 November 2012 - 07:14 PM

Better to learn Java rather than stupid fancy presentations
We are professional here targeting to code not to show :)

Post your actionPerformed() method so we'll see what you do not do rigth
Was This Post Helpful? 0
  • +
  • -

#3 fritozy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-November 12

Re: Giving (static JButton Increase=new JButton) a numerical value?

Posted 29 November 2012 - 07:36 PM

-I believe this is what you are talking about-

}
};

JFrame frame = new JFrame( );
Increase.addActionListener( new ActionListener()






{
public void actionPerformed(ActionEvent e)
{
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Giving (static JButton Increase=new JButton) a numerical value?

Posted 29 November 2012 - 07:56 PM

And why is your JButton declared as static ?

This is usually a sign of really bad OO design

The only static thing should be the main() method that fires up your application
Was This Post Helpful? 0
  • +
  • -

#5 fritozy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-November 12

Re: Giving (static JButton Increase=new JButton) a numerical value?

Posted 29 November 2012 - 08:12 PM

I dont know if this is a good response to yours but I have a second class running the main body class all in a default package. Dont think you can fully help me without me giving you the full program so here it is. Im having a hard time asking the correct questions and responding to yours with my weak knowledge of the language. Have always had a hard time not talking with someone face to face.

Main body class
________________________________________________
I heavily appreciate your help and putting in your personal time for my issues.

This post has been edited by pbl: 29 November 2012 - 08:21 PM
Reason for edit:: Completly useless piece of code removed

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Giving (static JButton Increase=new JButton) a numerical value?

Posted 29 November 2012 - 08:19 PM

Don't want to be rude... but honnestly learn how to use arrays before trying to write such a piece of code as the horrible code you just posted
Was This Post Helpful? 0
  • +
  • -

#7 burakaltr  Icon User is online

  • D.I.C Regular

Reputation: 91
  • View blog
  • Posts: 274
  • Joined: 07-November 10

Re: Giving (static JButton Increase=new JButton) a numerical value?

Posted 29 November 2012 - 08:31 PM

Is this what you're trying to accomplish ?


import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;


public class Jb implements ActionListener {
	int count=0;
JButton but=new JButton(String.valueOf(count));
Jb(){
	JFrame j=new JFrame();
	j.add(but,BorderLayout.CENTER);
	j.setSize(400, 400);
	j.setDefaultCloseOperation(j.EXIT_ON_CLOSE);
	j.setVisible(true);j.pack();
but.addActionListener(this)	;
}
public static void main(String args[]){
	new Jb();
	
}
@Override
public void actionPerformed(ActionEvent arg0) {
	// TODO Auto-generated method stub
	count+=100;
	but.setText(String.valueOf(count));
}
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1