Created
July 19, 2010 14:56
-
-
Save justjkk/481509 to your computer and use it in GitHub Desktop.
IP Lab programs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import java.applet.*; | |
/* | |
<applet code="AWTControls" width=500 height=550> | |
</applet> | |
*/ | |
public class AWTControls extends Applet | |
implements ActionListener, ItemListener, | |
AdjustmentListener | |
{ | |
String btnMsg = ""; | |
String lstMsg = ""; | |
Button btnHard, btnSoft; | |
Checkbox chkC, chkCPP, chkJava; | |
CheckboxGroup cbgCompany; | |
Checkbox optTcs, optInfosys, optSyntel; | |
Scrollbar horzCurrent, vertExpected; | |
TextField txtName, txtPasswd; | |
TextArea txtaComments = new TextArea("", 5, 30); | |
Choice chCity; | |
List lstAccompany; | |
public void init() | |
{ | |
Label lblName = new Label("Name: "); | |
Label lblPasswd = new Label("Password: "); | |
Label lblField = new Label("Field of Interest: "); | |
Label lblSkill = new Label("Software Skills: "); | |
Label lblDreamComp = new Label("Dream Company: "); | |
Label lblCurrent = new Label("Current %: "); | |
Label lblExpected = new Label("Expected %: "); | |
Label lblCity = new Label("Preferred City: "); | |
Label lblAccompany = new Label("Accompanying Persons: "); | |
txtName = new TextField(15); | |
txtPasswd = new TextField(15); | |
txtPasswd.setEchoChar('*'); | |
btnHard = new Button("Hardware"); | |
btnSoft = new Button("Software"); | |
chkC = new Checkbox("C"); | |
chkCPP = new Checkbox("C++"); | |
chkJava = new Checkbox("Java"); | |
cbgCompany = new CheckboxGroup(); | |
optTcs = new Checkbox("Tcs", cbgCompany, true); | |
optInfosys = new Checkbox("Infosys", cbgCompany, false); | |
optSyntel = new Checkbox("Syntel", cbgCompany, false); | |
horzCurrent = new Scrollbar(Scrollbar.VERTICAL, 0, 1, 1, 101); | |
vertExpected = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 1, 101); | |
chCity = new Choice(); | |
chCity.add("Chennai"); | |
chCity.add("Bangalore"); | |
chCity.add("Hyderabad"); | |
chCity.add("Trivandrum"); | |
lstAccompany = new List(4, true); | |
lstAccompany.add("Father"); | |
lstAccompany.add("Mother"); | |
lstAccompany.add("Brother"); | |
lstAccompany.add("Sister"); | |
add(lblName); | |
add(txtName); | |
add(lblPasswd); | |
add(txtPasswd); | |
add(lblField); | |
add(btnHard); | |
add(btnSoft); | |
add(lblSkill); | |
add(chkC); | |
add(chkCPP); | |
add(chkJava); | |
add(lblDreamComp); | |
add(optTcs); | |
add(optInfosys); | |
add(optSyntel); | |
add(lblCurrent); | |
add(horzCurrent); | |
add(lblExpected); | |
add(vertExpected); | |
add(txtaComments); | |
add(lblCity); | |
add(chCity); | |
add(lblAccompany); | |
add(lstAccompany); | |
btnHard.addActionListener(this); | |
btnSoft.addActionListener(this); | |
chkC.addItemListener(this); | |
chkCPP.addItemListener(this); | |
chkJava.addItemListener(this); | |
optTcs.addItemListener(this); | |
optInfosys.addItemListener(this); | |
optSyntel.addItemListener(this); | |
horzCurrent.addAdjustmentListener(this); | |
vertExpected.addAdjustmentListener(this); | |
chCity.addItemListener(this); | |
lstAccompany.addItemListener(this); | |
} | |
public void actionPerformed(ActionEvent ae) | |
{ | |
String str = ae.getActionCommand(); | |
if(str.equals("Hardware")) | |
{ | |
btnMsg = "Hardware"; | |
} | |
else if(str.equals("Software")) | |
{ | |
btnMsg = "Software"; | |
} | |
repaint(); | |
} | |
public void adjustmentValueChanged(AdjustmentEvent ae) | |
{ | |
repaint(); | |
} | |
public void itemStateChanged(ItemEvent ie) | |
{ | |
repaint(); | |
} | |
public void paint(Graphics g) | |
{ | |
g.drawString("Detailed Profile:-", 10, 300); | |
g.drawString("Field of Interest: " + btnMsg, 10, 320); | |
g.drawString("Software Skill(s): ", 10, 340); | |
g.drawString("C: " + chkC.getState(), 10, 360); | |
g.drawString("C++: " + chkCPP.getState(), 10, 380); | |
g.drawString("Java: " + chkJava.getState(), 10, 400); | |
g.drawString("Dream Company: " | |
+ cbgCompany.getSelectedCheckbox().getLabel(), 10, 420); | |
g.drawString("Current %: " + horzCurrent.getValue(), 10, 440); | |
g.drawString("Expected %: " + vertExpected.getValue(), 10, 460); | |
g.drawString("Name: " + txtName.getText(), 10, 480); | |
g.drawString("Password" + txtPasswd.getText(), 10, 500); | |
g.drawString("Preferred City: " + chCity.getSelectedItem(), 10, 520); | |
int idx[]; | |
idx = lstAccompany.getSelectedIndexes(); | |
lstMsg = "Accompanying persons: "; | |
for(int i = 0; i < idx.length; i++) | |
lstMsg += lstAccompany.getItem(idx[i]); | |
g.drawString(lstMsg, 10, 540); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import java.applet.*; | |
// <applet code="BorderLayoutDemo" width="600" height="250"></applet> | |
public class BorderLayoutDemo extends Applet { | |
public void init() { | |
setLayout(new BorderLayout()); | |
add(new Button("KCG College of Technology"), BorderLayout.NORTH); | |
add(new Button("Karapakkam, Chennai-97."), BorderLayout.SOUTH); | |
add(new Button("Mission"), BorderLayout.EAST); | |
add(new Button("Vision"), BorderLayout.WEST); | |
String msg = "KCG College of Technology was established\n" | |
+ "in the year 1998 under the Hindustan Group of institutions \n" | |
+ "whose members have had consumate experience in the fields of \n" | |
+ "education and industry"; | |
add(new TextArea(msg), BorderLayout.CENTER); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import java.applet.*; | |
// <applet code="CardLayoutDemo" width="300" height="100"></applet> | |
public class CardLayoutDemo extends Applet | |
implements ActionListener, MouseListener{ | |
Checkbox chkVB, chkASP, chkJ2EE, chkJ2ME; | |
Panel pnlTech; | |
CardLayout cardLO; | |
Button btnMicrosoft, btnJava; | |
public void init() { | |
btnMicrosoft = new Button("Microsoft Products"); | |
btnJava = new Button("Java Products"); | |
add(btnMicrosoft); | |
add(btnJava); | |
cardLO = new CardLayout(); | |
pnlTech = new Panel(); | |
pnlTech.setLayout(cardLO); | |
chkVB = new Checkbox("Visual Basic"); | |
chkASP = new Checkbox("ASP"); | |
chkJ2EE = new Checkbox("J2EE"); | |
chkJ2ME = new Checkbox("J2ME"); | |
Panel pnlMicrosoft = new Panel(); | |
pnlMicrosoft.add(chkVB); | |
pnlMicrosoft.add(chkASP); | |
Panel pnlJava = new Panel(); | |
pnlJava.add(chkJ2EE); | |
pnlJava.add(chkJ2ME); | |
pnlTech.add(pnlMicrosoft, "Microsoft"); | |
pnlTech.add(pnlJava, "Java"); | |
add(pnlTech); | |
btnMicrosoft.addActionListener(this); | |
btnJava.addActionListener(this); | |
addMouseListener(this); | |
} | |
public void mousePressed(MouseEvent me) | |
{ | |
cardLO.next(pnlTech); | |
} | |
public void mouseClicked(MouseEvent me){} | |
public void mouseEntered(MouseEvent me){} | |
public void mouseExited(MouseEvent me){} | |
public void mouseReleased(MouseEvent me){} | |
public void actionPerformed(ActionEvent ae) | |
{ | |
if(ae.getSource() == btnMicrosoft) | |
{ | |
cardLO.show(pnlTech, "Microsoft"); | |
} | |
else | |
{ | |
cardLO.show(pnlTech, "Java"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import java.applet.*; | |
// <applet code="FlowLayoutDemo" width="300" height="300"> </applet> | |
public class FlowLayoutDemo extends Applet implements ItemListener { | |
Checkbox chkWinXP, chkWinVista, chkMac, chkLinux; | |
public void init() { | |
setLayout(new FlowLayout(FlowLayout.LEFT)); | |
Label lblOS = new Label("Operating System(s) Knowledge"); | |
chkWinXP = new Checkbox("Windows XP"); | |
chkWinVista = new Checkbox("Windows Vista"); | |
chkMac = new Checkbox("Macintosh"); | |
chkLinux = new Checkbox("Linux"); | |
add(lblOS); | |
add(chkWinXP); | |
add(chkWinVista); | |
add(chkMac); | |
add(chkLinux); | |
chkWinXP.addItemListener(this); | |
chkWinVista.addItemListener(this); | |
chkMac.addItemListener(this); | |
chkLinux.addItemListener(this); | |
} | |
public void itemStateChanged(ItemEvent ie) { | |
repaint(); | |
} | |
public void paint(Graphics g) { | |
g.drawString("Operating System(s) Knowledge: ", 10, 130); | |
g.drawString("Windows XP: "+chkWinXP.getState(), 10, 150); | |
g.drawString("Windows Vista: "+chkWinVista.getState(), 10, 170); | |
g.drawString("Macintosh: "+chkMac.getState(), 10, 190); | |
g.drawString("Linux: "+chkLinux.getState(), 10, 210); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.applet.*; | |
//<applet code="GridBagLayoutDemo" width="800" height="300"></applet> | |
public class GridBagLayoutDemo extends Applet { | |
GridBagLayout gb = new GridBagLayout(); | |
public void init() { | |
setLayout(gb); | |
GridBagConstraints cons = new GridBagConstraints(); | |
cons.fill = GridBagConstraints.BOTH; | |
Label lbl1 = new Label("First"); | |
cons.gridx = 0; | |
cons.gridy = 0; | |
cons.gridwidth = 1; | |
cons.gridheight = 1; | |
cons.weightx = 0; | |
cons.weighty = 1; | |
add(lbl1); | |
Button btn1 = new Button("Button 1"); | |
cons.gridx = 1; | |
cons.gridy = 0; | |
cons.weightx = 1; | |
gb.setConstraints(btn1, cons); | |
add(btn1); | |
Button btn2 = new Button("Button 2"); | |
cons.gridx = 1; | |
cons.gridy = 1; | |
cons.weightx = 1; | |
gb.setConstraints(btn2, cons); | |
add(btn2); | |
Label lbl2 = new Label("Second"); | |
cons.gridx = 4; | |
cons.gridy = 0; | |
gb.setConstraints(lbl2, cons); | |
add(lbl2); | |
Button btn3 = new Button("Button 3"); | |
cons.gridx = 2; | |
cons.gridy = 0; | |
gb.setConstraints(btn3, cons); | |
add(btn3); | |
TextField tf = new TextField("TextField"); | |
cons.gridx = 0; | |
cons.gridy = 2; | |
cons.gridwidth = 4; | |
cons.gridheight = 1; | |
cons.fill = GridBagConstraints.HORIZONTAL; | |
cons.anchor = GridBagConstraints.CENTER; | |
gb.setConstraints(tf, cons); | |
add(tf); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.applet.*; | |
// <applet code="GridLayoutDemo" width="300" height="300"></applet> | |
public class GridLayoutDemo extends Applet { | |
public void init() { | |
setLayout(new GridLayout(4,4)); | |
setFont(new Font("Sans Serif", Font.BOLD, 24)); | |
for(int i = 1; i <= 15; i++) | |
add(new Button("" + i)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment