b == setButton should work since == asks if two variables reference the same object. But look into setting the command name or using multiple actionListeners for more flexibility.


From: "Jason Carlamere" <[EMAIL PROTECTED]>
Reply-To: "jdjlist" <[EMAIL PROTECTED]>
To: "jdjlist" <[EMAIL PROTECTED]>
Subject: [jdjlist] Re: trying to master Buttons....
Date: Mon, 24 Feb 2003 08:23:03 -0500


1 more thing


if (b == setButton) wont work

you can say if b instanceof Button

or set the name of setButton to setButton.setName("setButton")

and in the action check on the name

if(b instanceof Button)
      if (b.getName().equals("setButton")
            //then do stuff





Without the wind, the grass does not move. Without software, networks and
hardware are useless



"Tim Nicholson"
<tim80 To: "jdjlist" <[EMAIL PROTECTED]>
@bigpond.com> cc:
Subject: [jdjlist] trying to master Buttons....
02/24/2003 09:00
AM
Please respond
to "jdjlist"







Hi list,


I am trying to master Buttons -- and have been having a few problems.

First I have 1 or 2 questions :-

1) What is the difference between a Button and a JButton ? Or in the same
way, between a Frame and a JFrame ?

Button seems to be a class in the java.awt library. But what about if you
put a "J" in front of it ?

2) My problem at the moment is trying to get my Button in the code below to
match up to my expectations. I managed to get a GUI going and to
incorporate a Button into it -- but the problem is that the Button takes up
half of the GUI (the top half). I wanted a nice small Button and in a place
where I could choose to put it. Instead what I got was this huge thing that
takes up half the screen and I have no say as to where I would like to put
it.

Can someone give me some pointers as to how I can modify my code to achieve
what I want ?


//--------------------------------------------------------------------


import java.awt.*;
import java.awt.event.*;

public class File1 extends Frame implements ActionListener{

//button is a GUI component
//GUI (Graphic User Interface

private Button setbutton;


public File1() {


setLayout(new GridLayout(3,2));

 setbutton = new Button("SET");
 add(setbutton);
 setbutton.addActionListener(this);

 setSize(300,100);
 setTitle("Kitchen System");
 setVisible(true);

}//end of constructor

//---------------------------------------------------------------
//actionPerformed
//---------------------------------------------------------------

public void actionPerformed (ActionEvent e) {
 Button b = (Button)e.getSource();

 if (b == setbutton)
 {

}//end of if


}//end of actionPerf



public static void main(String [] args) { new File1();

}

}//end of class
---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to
[EMAIL PROTECTED]
http://www.sys-con.com/fusetalk





---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
http://www.sys-con.com/fusetalk


_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963



--- You are currently subscribed to jdjlist as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] http://www.sys-con.com/fusetalk

Reply via email to