• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java people: I need help, PLEASE!!

trmiv

Lifer
OK, this is REALLY basic stuff for you Java gurus, but I'm just learning. Here is the problem as it appears in my book:



<< You can change the size of an applet by using the setSize(int h, int v) method. Write an applet that contains two Buttons, labeled &quot;Big&quot; and &quot;Small.&quot; Whenever the user clicks on small, set the applet's dimensions to 200 x 100, and whenever the user clicks on big, set the dimensions to 300 x 200. >>



And this is the code that I have so far:


<<

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class SimpleApplet extends Applet implements ActionListener
{

private Button changeBig;
private Button changeSmall;

public void init()
{

changeBig = new Button(&quot;Big&quot😉;
changeBig.addActionListener(this);
changeSmall = new Button(&quot;Small&quot😉;
changeSmall.addActionListener(this);

add(changeBig);
add(changeSmall);
setSize(300, 200);
}

public void actionPerformed(ActionEvent e)
{
if (e.getSource() == changeBig)
setSize(300,200);
else if (e.getSource() == changeSmall)
setSize(200, 100);
}
}
>>



When I run this in Internet Explorer, it gives me a grey box with the two buttons towards the top, but clicking on them does nothing. I don't think the setSize() method is doing anything though, because the initial setSize() under the init() doesn't even work. No matter what I change that value to, the applet is always the default size when it starts up, then pressing the buttons does nothing. What am I doing wrong here?
 
Back
Top