View Single Post
  #2 (permalink)  
Old 05-13-2008, 05:03 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 228
Eku is on a distinguished road
About the JFrame.
You can use this format. i just created a simple Structure that can guide you.

Code:
import javax.swing.*; //Loads the Swing Components which contains the Jframe and others import java.awt.*; //Loads AWT which contains the container and Listener if you like to use buttons //Global Declarations private JLabel A = new Jbutton(); //adding extends & implements enable the use of Jframe and Action Listeners public class Main extends JFrame implements ActionListener{ JFrame Samp = new JFrame(); Samp.setTitle("This is my Program"); //Set the Title Samp.setBounds(100, 100, 800, 600); //(set the location and size) Samp.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Samp.setVisible(true); //This will open your Gui Container container = this.getContentPane(); //set a container // From this on you can add buttons, textfields, etc to the container container.setLayout(null); //setting it to null but you can use other layouts on this //Example of adding a button Jbutton A = new Jbutton("Compute Quantity"); A.addActionListener(this); //adds a listener A.setBounds(x,y,Width,Ht); //This are in pixels, set the location container.add(A); // finally adds the button to the container //Example of adding a label A.setText("Output Here"); A.addActionListener(this); //adds a listener A.setBounds(x,y,Width,Ht); //This are in pixels, set the location container.add(A); // finally adds the button to the container //Add more components here see tutorials for other components =) } //Here is were the action listener awaits =) public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if(command.equalsIgnoreCase("Compute Quantity")){ //Quantity equation here //Display the output to a textfield/Label/TextArea A.setText(Output Here); //Change the display of A (Jlabel) } else if (command.equalsIgnoreCase("Other buttons")){ } else if (command.equalsIgnoreCase("Other buttons2")){ } } }
I hope this Helps. =P

Last edited by Eku : 05-13-2008 at 06:01 AM.
Reply With Quote