Hi,
Unfortunately I have to do in this way as this is how we've been shown, so I'm sort of restricted in the manner I can do it. What I can't get is how on a button press I display another text field.
Main Topics
Browse All TopicsHi,,
Just started in Java and I have to code a Java Applet that displays 2 buttons one to draw a circle and the other to draw a rectangle when pressed. When the Circle button is pressed another box is displayed for the user to enter the radius of the circle, for a rectangle it displays 2 boxes for length and breadth. Using the input I have to draw a circle or rectangle. I then need another button called Calculate which will display the area and circumference of the circle.
I'm struggling getting the additional buttons displayed.
I've added what I have so far and would appreciate any help.
thanks
Heather
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
try something like this
/*
* Assignment2.java
*
* Created on 15 December 2008, 18:01
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package pkgAssignment2;
import java.awt.Button;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent
import java.awt.event.ActionListe
/**
*
* @author MOR08195294
*/
public class Assignment2 extends java.applet.Applet implements ActionListener
{
Font f = new Font("Timesroman", Font.PLAIN, 20);
Font f2 = new Font("Arial", Font.ITALIC, 14);
Label displayLabel, enterLabel;
TextField displayBox, enterBox;
TextField widthField = new TextField();
TextField heightField = new TextField();
Panel circle = new Panel();
Panel rectangle = new Panel();
Button drawCircle = new Button("Draw A Circle");
Button drawRectangle = new Button("Draw A Rectangle");
boolean isCircle = false, isRectangle = false;
String displayString, inputString;
/**
* Initialization method that will be called after the applet is loaded into
* the browser.
*/
public void init()
{
add(drawCircle);
add(drawRectangle);
drawCircle.addActionListen
drawRectangle.addActionLis
enterLabel = new Label("Enter");
enterBox = new TextField(12);
circle.add(enterLabel);
circle.add(enterBox);
rectangle.add(widthField);
rectangle.add(heightField)
}
// event-handlmg code
public void actionPerformed(ActionEven
{
if (e.getSource() == drawCircle)
{
isCircle = true;
isRectangle = false;
remove(rectangle);
add(circle);
invalidate();
validate();
}
if (e.getSource() == drawRectangle)
{
isCircle = false;
isRectangle = true;
remove(circle);
add(rectangle);
invalidate();
validate();
}
}
// TODO overwrite start(), stop() and destroy() methods
public void paint(Graphics gscreen)
{
gscreen.setColor(Color.red
if (isCircle)
{
gscreen.drawString("Displa
gscreen.drawOval(85, 45, 75, 75);
} else if (isRectangle)
{
gscreen.drawString("Displa
}
}
}
Business Accounts
Answer for Membership
by: CEHJPosted on 2008-12-31 at 01:48:07ID: 23268873
I would divide your display logic into the various screens using a CardLayout:
ooks/tutor ial/uiswin g/layout/ c ard.html
http://java.sun.com/docs/b