Results 1 to 7 of 7
Thread: Java GUI
- 04-23-2011, 03:01 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 23
- Rep Power
- 0
- 04-23-2011, 03:07 AM #2
Member
- Join Date
- Apr 2011
- Posts
- 23
- Rep Power
- 0
Using netbeans 6.9.1 for IDE
- 04-23-2011, 03:29 AM #3
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
What have you done so far? This isn't especially challenging, you should start here: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
Try seeing what you come up with and post your attempt here with some specific questions.
- 04-23-2011, 03:53 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 23
- Rep Power
- 0
GUI program
Thanks for responding
First of all, I'm using netbeans as the Ide. How do I open this file and extend the JFrame?
- 04-23-2011, 04:03 AM #5
I don't know what you mean by "open this file," any details would help.
But extending a JFrame is easy, example:
That's all there is to it.Java Code:import javax.swing.*; public class window extends JFrame { window() { super("JFrame Extension Example"); // Call this so we get a window title setSize(200, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } // This runs the program public static void main(String args[]) { window wnd = new window(); wnd.setVisible(true); // So we can see the window } }
ThaGood with: C/C++, DarkGDK, PHP, MySQL
Current reading: The Linux Programming Interface
- 04-23-2011, 04:23 AM #6
Member
- Join Date
- Apr 2011
- Posts
- 23
- Rep Power
- 0
Gui
I'm trying to write a similar program to this one.
I want to calculate feet and inches though
I want the program to have the ActionListener listen to the textfield for buttons being clicked
import java.awt.*;
import javax.swing.*;
public class FahrenheitGUI extends JFrame
{
private JLabel tempQuestionLabel = new JLabel( );
private JTextField tempBox = new JTextField( );
private JLabel tempAnswerLabel= new JLabel( );;
private Container contentPane;
private JButton submitButton = new JButton( );
public FahrenheitGUI ()
{
createGUI();
} // ends Welcome constructor
private void createGUI ( )
{
// get content pane and set the layout to null
contentPane = getContentPane();
contentPane.setBackground(Color.white);
contentPane.setLayout(null);
// set up the question label
tempQuestionLabel.setText ("Enter inches:");
tempQuestionLabel.setLocation(0,0);
tempQuestionLabel.setSize(200,30);
contentPane.add(tempQuestionLabel);
// set up the textfield for user entry
tempBox.setText("0");
tempBox.setLocation(210,0 );
tempBox.setSize(100,30 );
contentPane.add(tempBox);
// set up the submit button
submitButton.setText("Submit");
submitButton.setLocation(50,100);
submitButton.setSize(100,30);
contentPane.add(submitButton);
// set up the label where answer will be displayed
tempAnswerLabel.setText (" ");
tempAnswerLabel.setLocation(0,200);
tempAnswerLabel.setSize(300,30);
contentPane.add(tempAnswerLabel);
// set properties of window
setTitle ("Fahrenheit Program");
setSize(400,400);
setVisible(true);
}// ends creatGUI method.
public static void main ( String [] args )
{
FahrenheitGUI application = new FahrenheitGUI( );
application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}// ends main
}// ends program
- 04-23-2011, 04:53 AM #7
First, you need to add this statement to your imports
It has all the event functionality.Java Code:import java.awt.event.*;
Now, you can easily implement an action listener like this:
Java Code:anyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { // Put your code where for what you want to when you press a button } });
Also, when posting code here, please use the [code] tags.Good with: C/C++, DarkGDK, PHP, MySQL
Current reading: The Linux Programming Interface


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks