public void init() { setLayout(new GridLayout(2,3,20,35)); add (new Button("1")); add (new Button("1")); add (new Button("1")); add (new Button("1")); add (new Button("1")); add (new Button("1")); } } 象这种格式,谢谢你!
3.编写一个applet,包括一个复选框和一个文本编辑组件。复选框选中是不允许修改文本编辑组件的内容,不选中允许修改。 import java.awt.*; import java.awt.event.*; import java.applet.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Applet1 extends Applet implements ItemListener{ private boolean isStandalone = false; TextArea textArea1 = new TextArea(); BorderLayout borderLayout1 = new BorderLayout(); Panel panel1 = new Panel(); Choice choice1 = new Choice(); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } public void itemStateChanged(ItemEvent e) { String s = (String)e.getItem(); if(s.equals("可编辑")){ textArea1.setEditable(true);
{
public void mouseClicked(MouseEvent e)
{}
public void mouseEntered(MouseEvent e)
{
gb.setIcon(new ImageIcon("image/1.jpg"));
}
public void mouseExited(MouseEvent e)
{
gb.setIcon(new ImageIcon("image/2.jpg"));
}
}
);
import java.awt.event.*;
import java.applet.Applet;public class Applet1 extends Applet implements ActionListener
{
public void init()
{
setLayout(new GridLayout(2,3,20,35));
add (new Button("1"));
add (new Button("1"));
add (new Button("1"));
add (new Button("1"));
add (new Button("1"));
add (new Button("1"));
}
}
象这种格式,谢谢你!
import java.awt.*;
import java.awt.event.*;
import java.applet.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class Applet1 extends Applet implements ItemListener{
private boolean isStandalone = false;
TextArea textArea1 = new TextArea();
BorderLayout borderLayout1 = new BorderLayout();
Panel panel1 = new Panel();
Choice choice1 = new Choice(); //Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
public void itemStateChanged(ItemEvent e) {
String s = (String)e.getItem();
if(s.equals("可编辑")){
textArea1.setEditable(true);
}else {
textArea1.setEditable(false);
}
} //Construct the applet
public Applet1() {
} //Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
} //Component initialization
private void jbInit() throws Exception {
textArea1.setText("textArea1");
this.setLayout(borderLayout1);
choice1.addItem("可编辑");
choice1.addItem("不可编辑");
choice1.addItemListener(this);
this.add(textArea1, BorderLayout.CENTER);
this.add(panel1, BorderLayout.NORTH);
panel1.add(choice1, null);
} //Start the applet
public void start() {
} //Stop the applet
public void stop() {
} //Destroy the applet
public void destroy() {
} //Get Applet information
public String getAppletInfo() {
return "Applet Information";
} //Get parameter info
public String[][] getParameterInfo() {
return null;
} //Main method
public static void main(String[] args) {
Applet1 applet = new Applet1();
applet.isStandalone = true;
Frame frame;
frame = new Frame();
frame.setTitle("Applet Frame");
frame.add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400,320);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
}
这道题!!! greenmars2004(火球) 这么强,再写一下!谢谢
import java.awt.*;
import java.awt.event.*;
import java.applet.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class Applet2 extends Applet implements ItemListener{
private boolean isStandalone = false;
CheckboxGroup checkboxGroup1 = new CheckboxGroup();
// ButtonGroup bg = new ButtonGroup();
Checkbox checkbox1 = new Checkbox();
Checkbox checkbox2 = new Checkbox();
Checkbox checkbox3 = new Checkbox();
Checkbox checkbox4 = new Checkbox();
Checkbox checkbox5 = new Checkbox();
Checkbox checkbox6 = new Checkbox(); //Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
} //Construct the applet
public Applet2() {
} //Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public void itemStateChanged(ItemEvent e) {
if (checkbox1.getState()) {
Applet2.this.setBackground(Color.red);
}
else if (checkbox2.getState()) {
Applet2.this.setBackground(Color.BLUE);
}
else if(checkbox3.getState()){
Applet2.this.setBackground(Color.CYAN );
}
else if(checkbox4.getState()){
Applet2.this.setBackground(Color.darkGray );
}
else if(checkbox5.getState()){
Applet2.this.setBackground(Color.GREEN );
}
else if(checkbox6.getState()){
Applet2.this.setBackground(Color.yellow );
}
}
//Component initialization
private void jbInit() throws Exception {
this.setBackground(Color.red);
checkbox1.setCheckboxGroup(checkboxGroup1);
checkbox1.setLabel("red");
checkbox1.setState(true);
checkbox1.addItemListener(this);
checkbox2.setCheckboxGroup(checkboxGroup1);
checkbox2.setLabel("blue");
checkbox2.addItemListener(this);
checkbox3.setCheckboxGroup(checkboxGroup1);
checkbox3.setLabel("checkbox3");
checkbox3.addItemListener(this);
checkbox4.setCheckboxGroup(checkboxGroup1);
checkbox4.setLabel("checkbox4");
checkbox5.setCheckboxGroup(checkboxGroup1);
checkbox5.setLabel("checkbox5");
checkbox5.addItemListener(this);
checkbox6.setCheckboxGroup(checkboxGroup1);
checkbox6.setLabel("checkbox6");
checkbox6.addItemListener(this);
checkboxGroup1.setSelectedCheckbox(checkbox1);
this.add(checkbox1, null);
this.add(checkbox2, null);
this.add(checkbox3, null);
this.add(checkbox4, null);
this.add(checkbox5, null);
this.add(checkbox6, null);
} //Start the applet
public void start() {
} //Stop the applet
public void stop() {
} //Destroy the applet
public void destroy() {
} //Get Applet information
public String getAppletInfo() {
return "Applet Information";
} //Get parameter info
public String[][] getParameterInfo() {
return null;
} //Main method
public static void main(String[] args) {
Applet2 applet = new Applet2();
applet.isStandalone = true;
Frame frame;
frame = new Frame();
frame.setTitle("Applet Frame");
frame.add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400,320);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
}