aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exam tip & a question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exam tip & a question" Watch "Exam tip & a question" New topic
Author

Exam tip & a question

Basu Patel
Ranch Hand

Joined: May 28, 2000
Posts: 60
I would like to know if we are provided with a decimal to binary to hexadecimal to octadecimal calculator like the one provided with the windows operating system for the exam.All MCP papers are allowed to use the windows calculator.
Also I have a problem with the following code on java.awt,please refer below,the line: label.setText(s)
import java.awt.*;
import java.awt.event.*;
public class ButtonApp extends Frame {
Label label=new Label("Default Label");
Button b1=new Button("one");
Button b2=new Button("two");
Button b3=new Button("three");
Panel p1=new Panel();
Panel p2=new Panel();
public static void main(String[] args) {
ButtonApp obj=new ButtonApp();
}
public ButtonApp() {
super("ButtonApp");
p1.add(label);
b1.addActionListener(new ButtonHandler());
b2.addActionListener(new ButtonHandler());
b3.addActionListener(new ButtonHandler());
p1.add(b1);
p1.add(b2);
p1.add(b3);
add("North",p1);
add("Center",p2);
addWindowListener(new WindowEventHandler());
pack();
show();
}
}
class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
String s=e.getActionCommand();
/*here my compilor gives me an error saying that 'label' is an undefined variable or class name,please help! */
label.setText(s);
}
}
class WindowEventHandler extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}


<BR>Contact Me<BR> <A HREF="mailto:basu_patel@usa.net" rel="nofollow">basu_patel@usa.net</A> <P>
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Try this.
Remove the } which is after the show() method and place it after System.exit(0).
By doing this you are making the ButtonHandler and WindowEventHandler classes as the inner classes of ButtonApp Class. Now these two classes can access all the fields of ButtonApp.
[This is the whole point behind making inner classes. As a next step try making these two classes as anonymous classes of ButtonApp.]
- Srini

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exam tip & a question