|
||||||
| Java Tutorials Tutorials and Code for Java |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||||
|
This is the third of six tutorials that will show you how to create graphical user interfaces using java.
Prerequisites This tutorial is moderately difficult. If you know the Java basics please refer to my previous tutorials. If you do know the Java basics you should be familiar with my previous tutorials on GUI's. To read my tutorials please refer to my INDEX The Idea In order for your program to be attractive, the user must be able to easily navigate through your program. By creating a GUI the user is presented with all the features of the program in a clear and coherent manner. Adding buttons to your interface allow for user interaction which is the reason for a GUI. Although buttons look good, if they don’t do anything they have no meaning. Solution Since this tutorial assumes you know how to create a window and add a button to the window we will start off with that code. Code:
package cctuts;
import javax.swing.*;
public class InterfaceThree extends JFrame{
public InterfaceThree(){
setSize(400,400);
JButton startButton = new JButton("Start");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args){
new InterfaceThree();
}
}
Code:
package cctuts;
import java.awt.event.*;
import javax.swing.*;
public class InterfaceThree extends JFrame implements ActionListener{
public InterfaceThree(){
setSize(400,400);
JButton startButton = new JButton("Start");
add(startButton);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args){
new InterfaceThree();
}
}
Code:
package cctuts;
import java.awt.event.*;
import javax.swing.*;
public class InterfaceThree extends JFrame implements ActionListener{
public InterfaceThree(){
setSize(400,400);
JButton startButton = new JButton("Start");
add(startButton);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent a) {
}
public static void main(String[] args){
new InterfaceThree();
}
}
Code:
package cctuts;
import java.awt.event.*;
import javax.swing.*;
public class InterfaceThree extends JFrame implements ActionListener{
public InterfaceThree(){
setSize(400,400);
JButton startButton = new JButton("Start");
startButton.addActionListener(this);
add(startButton);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent a) {
}
public static void main(String[] args){
new InterfaceThree();
}
}
Code:
package cctuts;
import java.awt.event.*;
import javax.swing.*;
public class InterfaceThree extends JFrame implements ActionListener{
public InterfaceThree(){
setSize(400,400);
JButton startButton = new JButton("Start");
startButton.addActionListener(this);
add(startButton);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent a) {
for(int i = 0; true; i++){
System.out.println(i);
}
}
public static void main(String[] args){
new InterfaceThree();
}
}
![]() Last edited by John; 01-11-2007 at 03:10 PM. |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VB 6.0: Tutorial, How to Make Glass2K!! | TcM | VB Tutorials | 12 | 09-28-2008 11:53 AM |
| VB 6.0: Tutorial, How to make a GIF in your application | TcM | VB Tutorials | 17 | 07-01-2008 03:26 PM |
| Design/Php Partnership to work on a project to make income!!! | powermike92 | Request Services (Paid) | 3 | 11-03-2007 04:01 PM |
| How to make Dumplings | ahsan16 | The Lounge | 2 | 01-11-2007 10:55 PM |
| Java:Tutorial - Making multiple objects work differently | John | Java Tutorials | 0 | 01-11-2007 02:10 PM |
| Xav | ........ | 1357.94 |
| MeTh0Dz|Reb0rn | ........ | 1075.89 |
| WingedPanther | ........ | 919.18 |
| marwex89 | ........ | 906.86 |
| morefood2001 | ........ | 900.18 |
| John | ........ | 890.77 |
| Brandon W | ........ | 770.65 |
| chili5 | ........ | 312.39 |
| Steve.L | ........ | 264.99 |
| dcs | ........ | 232.34 |
Goal: 100,000 Posts
Complete: 83%