I used constructor for my form2 because in form 2 there no student name so i used constructor with parameters string name. i need to get the name print using clicking a button ,because that name is can used to class so can anyone send me the code to declare and to use any where in the method or in buttons
import java.awt.*;
import java.awt.event.*;
public class Main {
public static void main(String[] args) {
Frame frame = new Frame("Students");
final TextField name=new TextField();
name.setBounds(30,30, 120,10);
Button btn=new Button("Click");
btn.setBounds(30,80,40,10);
btn.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
name.setText("Name");
}
});
frame.add(btn);
frame.add(name);
frame.setLayout(null);
frame.setSize(500,500);
frame.setVisible(true);
}
}
Comments
Leave a comment