You are on page 1of 2

import java.awt.

*;
import java.awt.event.*;

1. Text Field

class TextDemo extends Frame{

TextField t1;

TextDemo(){
setSize(400,400);
setLayout(new FlowLayout(FlowLayout.LEFT));
t1=new TextField(20);
add(t1);

addWindowListner(new WindowAdaptor(){
public void windowClosing(WindowEvent we){
system.exit(0);

});
setVisible(true);
}
public static void main(String[] args){
new TextDemo();
}
}

2. Text Area
class TextDemo extends Frame{

TextArea t;

TextDemo(){
setSize(400,400);
setLayout(new FlowLayout(FlowLayout.LEFT));
t=new TextArea();
add(t);

addWindowListner(new WindowAdaptor(){
public void windowClosing(WindowEvent we){
system.exit(0);

});
setVisible(true);
}
public static void main(String[] args){
new TextDemo();
}
}

3. How to transfer data from frame to other

//Overload the constructor below “initcomponent” in Frame2

public Frame2(String para){


initcomponent();
jLabel1.setText(para);
}
// Go to the button action in Frame1

String msg = JTextField1.getText();


new Fram2(msg).setVisible(true);

You might also like