how to make a simple JButton on a JFrame window?
can anyone show me a demo how to make a JButton in a JFrame window...
please.. dont have any idea how to do it...
ill make it an input statement for some of my codes here.... i want to try that GUI instead of using JOptionPane's input dialog.
is there any link in java tutorials?
Re: how to make a simple JButton on a JFrame window?
Do you know how to create a JFrame?
Chris
Re: how to make a simple JButton on a JFrame window?
yes of course...
do i need to add the jbutton in a content pane?
i know how to instantiate a Jbutton object. i just dont know how to add it in the frame and how to use it as an input routine
Re: how to make a simple JButton on a JFrame window?
Code :
frame.add(new JButton());
And you canuse setActionListener() and setActionCommand() to set it up to detect it being pressed.
Chris
Re: how to make a simple JButton on a JFrame window?
If you are using a JFrame, you should make the call to (assuming your JFrame is named frame)
Code :
frame.getContentPane().add(new JButton());
In most circumstances you would add the JButton to a JPanel, along with any other things necessary (in your case perhaps a JLabel with a message?), then add that JPanel to the content pane, and as Freaky Chris describes add an action listener to the button to lister for events.
Re: how to make a simple JButton on a JFrame window?
Quote:
And you can use setActionListener() and setActionCommand() to set it up to detect it being pressed.
ahh so its not that easy to make the JButton as a simple input routine for my program...
any tnx for the information guys,,, ill post any further questions if necessary , coz i dont know how to use such methods...
Re: how to make a simple JButton on a JFrame window?
and i think i didnt post any particular cases in which i have to use a jbutton... im gonna check my console files first.. then ill post any codes here to convert it's input routines into a JButton interface
Re: how to make a simple JButton on a JFrame window?
this one..
Code :
public class SwitchSample4_EnumType {
private static enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
public static void main(String[] args) {
Day day = Day.values()[new Random().nextInt(Day.values().length)];
switch (day) {
case MONDAY:
System.out.println("Its Monday");
break;
case TUESDAY:
System.out.println("Its Tuesday");
break;
case WEDNESDAY:
System.out.println("Its Wednesday");
break;
case THURSDAY:
System.out.println("Its Thursday");
break;
case FRIDAY:
System.out.println("Its Friday");
break;
case SATURDAY:
System.out.println("Its Saturday");
break;
case SUNDAY:
System.out.println("Its Sunday");
break;
default:
System.out.println("what day is it?");
break;
}
}
}
how can i make a simple GUI in Jframe for this code... make the switch cases the value for the JBUtton....
get it?
i mean... it will be the value for every button
Re: how to make a simple JButton on a JFrame window?
Here is, in my opinion, the most interesting part:
JAVA Code:
//If first time key in date run statement
if(first == 0){
++first;//Track if is the first record key in
items[i] = new Item(itemNumber, itemDesc, sellPrice, quantity);
}
//Else continue key in record
else{
entries = items[0].getEntries();//Get number of entries entered
for(j=0; j<entries; ++j){
duplicate = items[j].equals(itemNumber, itemDesc, sellPrice, quantity);//Check for duplication of entries
if(duplicate == true) {
Print.duplicateError();
--i;
--looping;
break;
}
}
if(duplicate == false)//else save record
items[entries] = new Item(itemNumber, itemDesc, sellPrice, quantity);
}