Sunday, August 18, 2013

How to create UI using AWT in java

import java.awt.*;
class frame extends Frame{

public frame(String title){
/* Initialization*/
super(title);
setSize(400, 300);

// get screen size
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension fr = getSize();

int xpos = screen.width / 2 - fr.width / 2;
int ypox = screen.height / 2 - fr.height / 2;

// set center screen
setLocation(xpos, ypox);
setVisible(true);

/*Add components*/
init();

/*Add Event*/
start();

}

public void init(){
// write code to add components into frame
}

public void start(){
// create events for control
}
}

public class AWTTest {
public static void main(String[] args){
new frame("Demo");
}
}

No comments:

Post a Comment