import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet cod
ID: 3633747 • Letter: I
Question
import java.awt.*;import java.awt.event.*;
import java.applet.*;
/*
<applet code="Project" width=400 height=400>
</applet>
*/
public class Project extends Applet implements ActionListener
{
String msg="";
String ban="";
String h1="";
String nuln = " " ;
Button History_Civics,Geography,Science,Maths,Computer_Application,English;
public void init()
{
History_Civics= new Button("History_Civics");
Science= new Button("Science");
Geography= new Button("Geography");
Maths= new Button("Maths");
Computer_Application= new Button("Computer_Application");
English= new Button("English");
h1="**************************************************" +
"************Welcome to Syllabus viewer***********" +
"************************************************" ;
add(History_Civics);
add(Science);
add(Geography);
add(Maths);
add(Computer_Application);
add(English);
History_Civics.addActionListener(this);
Science.addActionListener(this);
Geography.addActionListener(this);
Maths.addActionListener(this);
Computer_Application.addActionListener(this);
English.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("History_Civics"))
{
msg= " Syllabus for History_Civics : "+ nuln +
"SECTION A: CIVICS"+ nuln +
"1. The Legislature" + nuln +
"(a) The Union Parliament: the Rajya Sabha and Lok Sabha. "+ nuln +
"The Union Parliament - definition of Parliament. "+ nuln +
"It must be clearly explained as an important aspect of a federal setup in India."+ nuln +
"A brief idea of two levels of authority (Central and State Levels). "+ nuln +
"i) Lok Sabha - term, composition, qualification for membership,disqualification of membership."+ nuln +
"Parliamentary procedures: a brief idea of sessions, quorum, question hour, motions– adjournment and no-confidence motion. "+ nuln +
"Speaker – A brief idea of his selection, role, functions."+ nuln ;
}
else if(str.equals("Science"))
msg= "Syllabus for Science";
else if(str.equals("Geography"))
msg= "Syllabus for Geography";
else if(str.equals("Maths"))
msg= "Syllabus for Maths";
else if(str.equals("Computer_Application"))
msg= "Syllabus for Computer_Application";
else
msg= "Syllabus for English";
repaint();
}
public void paint(Graphics g)
{
ban="Click on the button to view Syllabus";
g.drawString(h1,100,50);
g.drawString(ban,300,80);
g.drawString(msg,10,250);
History_Civics.setBounds(50, 100 , 100 , 100);
Science.setBounds(150, 100 , 100 , 100);
Geography.setBounds(250, 100 , 100 , 100);
Maths.setBounds(350, 100 , 100 , 100);
Computer_Application.setBounds(450, 100 , 150 , 100);
English.setBounds(600, 100 , 100 , 100);
}
}
Explanation / Answer
please rate - thanks
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="Project" width=400 height=400>
</applet>
*/
public class Project extends Applet implements ActionListener
{
String msg="";
String ban="";
String h1="";
String nuln = " " ;
Button History_Civics,Geography,Science,Maths,Computer_Application,English;
public void init()
{
History_Civics= new Button("History_Civics");
Science= new Button("Science");
Geography= new Button("Geography");
Maths= new Button("Maths");
Computer_Application= new Button("Computer_Application");
English= new Button("English");
h1="**************************************************" +
"************Welcome to Syllabus viewer***********" +
"************************************************" ;
add(History_Civics);
add(Science);
add(Geography);
add(Maths);
add(Computer_Application);
add(English);
History_Civics.addActionListener(this);
Science.addActionListener(this);
Geography.addActionListener(this);
Maths.addActionListener(this);
Computer_Application.addActionListener(this);
English.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("History_Civics"))
{
msg= " Syllabus for History_Civics : "+ nuln +
"SECTION A: CIVICS"+ nuln +
"1. The Legislature" + nuln +
"(a) The Union Parliament: the Rajya Sabha and Lok Sabha. "+ nuln +
"The Union Parliament - definition of Parliament. "+ nuln +
"It must be clearly explained as an important aspect of a federal setup in India."+ nuln +
"A brief idea of two levels of authority (Central and State Levels). "+ nuln +
"i) Lok Sabha - term, composition, qualification for membership,disqualification of membership."+ nuln +
"Parliamentary procedures: a brief idea of sessions, quorum, question hour, motions– adjournment and no-confidence motion. "+ nuln +
"Speaker – A brief idea of his selection, role, functions."+ nuln ;
}
else if(str.equals("Science"))
msg= "Syllabus for Science";
else if(str.equals("Geography"))
msg= "Syllabus for Geography";
else if(str.equals("Maths"))
msg= "Syllabus for Maths";
else if(str.equals("Computer_Application"))
msg= "Syllabus for Computer_Application";
else
msg= "Syllabus for English";
repaint();
}
public void paint(Graphics g)
{
ban="Click on the button to view Syllabus";
g.drawString(h1,100,50);
g.drawString(ban,300,80);
int startX=10,startY=250;
for (String line : msg.split(" ")) //split string into smaller ones delimited by
{ g.drawString(line, startX, startY += g.getFontMetrics().getHeight()); //and print each one
} //height of the font gets added to startY each time to force the print to the next line
//g.drawString(msg,10,250);
History_Civics.setBounds(50, 100 , 100 , 100);
Science.setBounds(150, 100 , 100 , 100);
Geography.setBounds(250, 100 , 100 , 100);
Maths.setBounds(350, 100 , 100 , 100);
Computer_Application.setBounds(450, 100 , 150 , 100);
English.setBounds(600, 100 , 100 , 100);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.