download here zip file
package bookform;
import java.awt.BorderLayout; import java.awt.Button; import java.awt.Container;
import java.awt.FlowLayout; import java.awt.Frame; import java.awt.GridLayout;import java.awt.Label; import java.awt.Panel; import java.awt.TextArea;
import java.awt.TextField; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class BookForm extends Frame{
private TextField tfc,tft,tfp;private Button bti,btc,bte;
private TextArea out;
public void initForm(){
setSize(400, 500);
setVisible(true);
setLocationRelativeTo(null);
setTitle("BookForm");
closeForm();
}
private void initControls() {
Panel p1 =new Panel(); p1.setLayout(new FlowLayout());
p1.add(new Label("BookForm")); Panel p2 =new Panel();
p2.setLayout(new GridLayout(3, 2)); p2.add(new Label("Code:"));
p2.add(tfc=new TextField()); p2.add(new Label("Title"));
p2.add(tft=new TextField()); p2.add(new Label("Price"));
p2.add(tfp=new TextField()); Panel p3 = new Panel();
p3.setLayout(new FlowLayout()); p3.add(bti=new Button("Insert"));
p3.add(btc=new Button("Clear")); p3.add(bte=new Button("Exit"));
Panel p4 =new Panel(); p4.setLayout(new FlowLayout());
p4.add(out =new TextArea(10,50)); Panel p12=new Panel();
p12.setLayout(new BorderLayout()); p12.add(p1,BorderLayout.NORTH);
p12.add(p2,BorderLayout.CENTER); Panel p34=new Panel();
p34.setLayout(new BorderLayout()); p34.add(p3,BorderLayout.NORTH);
p34.add(p4,BorderLayout.CENTER); Panel p1234=new Panel();
p1234.setLayout(new BorderLayout()); p1234.add(p12,BorderLayout.NORTH);
p1234.add(p34,BorderLayout.CENTER);
add(p1234);
}
public BookForm(){ initForm(); initControls(); myevent(); }
private void myevent() {
bte.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
btc.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tfc.setText(""); tft.setText(""); tfp.setText("");
}
});
bti.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String code=tfc.getText();
String title=tft.getText();
String price=tfp.getText();
String data=code+" "+title+" "+price+"\n";
out.append(data);
}
});
}
public void closeForm(){addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e)
{System.exit(0);}
});
}
public static void main(String[] args) {
new BookForm();
}
}
No comments:
Post a Comment