With the below program, am trying to find the names assigned to all the components part of the GUI.
public class AWTCounter extends Frame implements ActionListener{
private Label lblCount; //Declare component Label
private TextField tfCount; //Declare component TextField
private Button btnCount; //Declare component Button
public AWTCounter(){
this.setLayout(new FlowLayout());
lblCount = new Label("Counter"); // construct Label
this.add(lblCount); // "super" Frame adds label
tfCount = new TextField("0", 10); // construct TextField
tfCount.setEditable(false); // set to read-only
this.add(tfCount); // 'super" Frame adds tfCount
btnCount = new Button("Count"); // construct button
this.add(btnCount); // "super" Frame adds button
btnCount.addActionListener(this);
// Clicking Button source fires ActionEvent
// btnCount registers this instance as ActionEvent listener
setTitle("AWT Counter"); // "super" Frame sets title
setSize(250, 100); // "super" Frame sets initial window size
System.out.println(this);
System.out.println(lblCount);
System.out.println(tfCount);
System.out.println(btnCount);
this.setVisible(true); // "super" Frame shows
System.out.println(this);
System.out.println(lblCount);
System.out.println(tfCount);
System.out.println(btnCount);
}
. . . . . .
}
here is the output on console:
AWTCounter[frame0,0,0,250x100,invalid,hidden,layout=java.awt.FlowLayout,title=AWT Counter,resizable,normal]
java.awt.Label[label0,0,0,0x0,invalid,align=left,text=Counter]
java.awt.TextField[textfield0,0,0,0x0,invalid,text=0,selection=0-0]
java.awt.Button[button0,0,0,0x0,invalid,label=Count]
AWTCounter[frame0,0,0,250x100,layout=java.awt.FlowLayout,title=AWT Counter,resizable,normal]
java.awt.Label[label0,20,35,58x23,align=left,text=Counter]
java.awt.TextField[textfield0,83,35,94x23,text=0,selection=0-0]
java.awt.Button[button0,182,35,47x23,label=Count]
Based on the above output, I see some dynamic names like button0
/label0
/frame0
/...
My question:
Is label0
, attribute member value of class Label
? If yes, what is the attribute member name of class Label
?
Note: I am Java beginner
Aucun commentaire:
Enregistrer un commentaire