Hello,
I am creating simple an applet to draw a registration form based on the selected item within the awt choice object.
I have include a radio button, choice list and button.
My problem is when running the Applet...the choice list is blinking and when I maximized or minimise frame the component will be repeatedly to whole frame...
Can someone please help explain how exactly to create a button, choice and radio button?
Thanks :)
import java.awt.*;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Choice;
import java.awt.event.*;
import java.applet.Applet;
public class Student extends Applet implements ItemListener {
public void paint(Graphics g)
{
LayoutManager Layout;
Layout = new FlowLayout();
setLayout(Layout);
super.paint( g );
//*************************************************************
//Straight Line
g.drawLine(30,30,750,30); //upper (x1,y1,x2,y2)
g.drawLine(30,110,750,110); //header
g.drawLine(30,30,30,670); //left
g.drawLine(750,30,750,670); //right
g.drawLine(30,480,750,480); //center
g.drawLine(30,510,750,510); //center2
g.drawLine(30,670,750,670); //bottom
//*************************************************************
//Header
g.setFont(new Font("Tahoma",Font.BOLD,32));
g.drawString("Student Registration Form",190,80);
g.setFont(new Font("Tahoma",Font.BOLD,22));
g.drawString("Family Details",35,505);
//*************************************************************
//On Left Side(change y(+40))
g.setFont(new Font("Arial",Font.PLAIN,16)); //Name
g.drawString("Name :",50,150);
g.setFont(new Font("Arial",Font.PLAIN,16)); //IC
g.drawString("No. IC :",50,190);
g.setFont(new Font("Arial",Font.BOLD,10));
g.drawString("(900209-01-6537)",285,195);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Age
g.drawString("Age :",50,230);
//g.setFont(new Font("Arial",Font.BOLD,16));
//g.drawString("years",175,233);
g.setFont(new Font("Arial",Font.PLAIN,16)); //DOB
g.drawString("Date of Birth :",50,270);
g.setFont(new Font("Arial",Font.PLAIN,16)); //POB
g.drawString("Place of Birth :",50,310);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Race
g.drawString("Race :",50,350);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Gender
g.drawString("Gender :",50,390);
//*************************************************************
//On Right Side
g.setFont(new Font("Arial",Font.PLAIN,16)); //Address
g.drawString("Address :",390,150);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Postcode
g.drawString("Postcode :",390,190);
g.setFont(new Font("Arial",Font.PLAIN,16)); //State
g.drawString("State :",390,230);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Phone(H)
g.drawString("Telephone(h) :",390,270);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Phone(M)
g.drawString("Telephone(m) :",390,310);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Course
g.drawString("Course :",390,355);
//*************************************************************
//Family Details
g.setFont(new Font("Arial",Font.PLAIN,16)); //Father
g.drawString("Father Name :",50,550);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Occupation
g.drawString("Occupation :",50,590);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Mother
g.drawString("Mother Name :",390,550);
g.setFont(new Font("Arial",Font.PLAIN,16)); //Occupation
g.drawString("Occupation :",390,590);
//*************************************************************
//Rectangle TextBox (change y1(+40))
g.drawRect(120,133,245,25); //Name (x1,y1,width,height)
g.drawRect(120,173,160,25); //IC
g.drawRect(155,213,50,25); // Age
g.drawRect(155,253,190,25); // DOB
g.drawRect(155,293,190,25); // POB
//g.drawRect(155,333,190,25); // Race
g.setFont(new Font("Arial",Font.PLAIN,16)); //Name
g.drawString("Nuramira binti Ibrahim",123,153);
g.drawRect(500,133,225,25); // Address
g.drawRect(500,173,80,25); // Postcode
g.drawRect(500,210,190,25); // State
g.drawRect(500,253,205,25); // Tel(h)
g.drawRect(500,293,205,25); // Tel(p)
g.drawRect(155,535,210,25); // Father
g.drawRect(155,575,210,25); // Position
g.drawRect(495,535,215,25); // Mother
g.drawRect(495,575,215,25); // Position
//*************************************************************
//Button
Button regButton, resetButton; //declaration
regButton = new Button("Register");
regButton.setBounds(310,640,70,25); // x,y,width,height
add(regButton);
resetButton = new Button("Reset");
resetButton.setBounds(390,640,70,25); // x,y,width,height
add(resetButton);
//*************************************************************
//Choice Race
Choice race = new Choice(); //declaration + constructor
race.add("Malay");
race.add("Chinesse");
race.add("Indian");
race.setBounds(155,335,190,25); // x,y,width,height
add(race);
race.addItemListener(this);
//Choice Course
Choice course;
course = new Choice(); //declaration + constructor
course.addItem("JTMK");
course.addItem("JKE");
course.addItem("JKA");
course.addItem("JKM");
course.addItem("Perd");
course.setBounds(500,340,60,25);
add(course);
Choice.addItemListener(this);
//*************************************************************
//radio button
CheckboxGroup radioGroup; // necessary to only allow one radio button to be selected at the same time.
Checkbox radioM, radioF; // declaration
radioGroup = new CheckboxGroup();
radioM = new Checkbox("Male", radioGroup,false);
radioF = new Checkbox("Female", radioGroup,true);
radioM.setBounds(155,375,50,30);
radioF.setBounds(215,375,70,30);
add(radioM);
add(radioF);
radioM.addItemListener(this);
radioF.addItemListener(this);
}
}