当前位置: 技术问答>java相关
java程序问题
来源: 互联网 发布时间:2015-01-09
本文导语: 源代码如下: import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class GridBagLayoutTest extends Applet { public void init() { //setLayout(new BorderLayout()); ThreeDPanel p=new ThreeDPanel(); p.add(new ButtonPurchForm()); add(p...
源代码如下:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class GridBagLayoutTest extends Applet
{
public void init()
{
//setLayout(new BorderLayout());
ThreeDPanel p=new ThreeDPanel();
p.add(new ButtonPurchForm());
add(p);
}
}
class ThreeDPanel extends Panel
{
public void paint(Graphics g)
{
g.setColor(Color.lightGray);
g.draw3DRect(0,0,getSize().width-1,getSize().height-1,true);
}
}
class ButtonPurchForm extends Panel
{
Button Purch=new Button("Purchase Something Now");
public void ButtonPurchForm()
{
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
setLayout(gbl);
Purch.setFont(new Font("Times-Roman",Font.BOLD+Font.ITALIC,16));
gbc.gridwidth=4;
add(Purch,gbc);
//Separator sep=new Separator();
//gbc.gridwidth=4;
//gbc.insets=new Insets(0,0,10,0);
//add(sep);
Label Name=new Label("Name:");
gbc.gridwidth=1;
gbc.anchor=GridBagConstraints.WEST;
add(Name,gbc);
TextField NameTextField=new TextField(25);
gbc.gridwidth=GridBagConstraints.REMAINDER;
add(NameTextField,gbc);
Label Address=new Label("Address:");
gbc.gridwidth=1;
gbc.anchor=GridBagConstraints.WEST;
add(Address,gbc);
TextField AddrTextField=new TextField(25);
gbc.gridwidth=3;
add(AddrTextField,gbc);
Label City=new Label("City:");
gbc.gridwidth=1;
add(City,gbc);
TextField CityTextField=new TextField(15);
gbc.gridwidth=1;
add(CityTextField,gbc);
Label State=new Label("State:");
gbc.gridwidth=1;
add(State,gbc);
TextField StateTextField=new TextField(10);
gbc.gridwidth=1;
add(StateTextField,gbc);
Label PurchM=new Label("Purchase Method:");
gbc.gridwidth=1;
add(PurchM,gbc);
Choice Pay=new Choice();
Pay.add("VISA");
Pay.add("MasterCard");
Pay.add("COD");
gbc.gridwidth=3;
gbc.fill=GridBagConstraints.NONE;
add(Pay,gbc);
//Separator sep2=new Separator();
//gbc.gridwidth=GridBagConstraints.REMAINDER;
//gbc.fill=GridBagConstraints.BOTH;
//add(sep2);
Button PurchButton=new Button("Purchase");
gbc.gridwidth=2;
gbc.anchor=GridBagConstraints.CENTER;
gbc.fill=GridBagConstraints.NONE;
add(PurchButton,gbc);
Button Cancel=new Button("Cancel");
gbc.gridwidth=2;
gbc.anchor=GridBagConstraints.CENTER;
add(Cancel,gbc);
}
}
这里我想显示一个表单的布局,不过怎么显示也出不来,我不知道错在那里,那位高手能指点一下,最好能解释一下错在那里,谢谢了。:)
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class GridBagLayoutTest extends Applet
{
public void init()
{
//setLayout(new BorderLayout());
ThreeDPanel p=new ThreeDPanel();
p.add(new ButtonPurchForm());
add(p);
}
}
class ThreeDPanel extends Panel
{
public void paint(Graphics g)
{
g.setColor(Color.lightGray);
g.draw3DRect(0,0,getSize().width-1,getSize().height-1,true);
}
}
class ButtonPurchForm extends Panel
{
Button Purch=new Button("Purchase Something Now");
public void ButtonPurchForm()
{
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
setLayout(gbl);
Purch.setFont(new Font("Times-Roman",Font.BOLD+Font.ITALIC,16));
gbc.gridwidth=4;
add(Purch,gbc);
//Separator sep=new Separator();
//gbc.gridwidth=4;
//gbc.insets=new Insets(0,0,10,0);
//add(sep);
Label Name=new Label("Name:");
gbc.gridwidth=1;
gbc.anchor=GridBagConstraints.WEST;
add(Name,gbc);
TextField NameTextField=new TextField(25);
gbc.gridwidth=GridBagConstraints.REMAINDER;
add(NameTextField,gbc);
Label Address=new Label("Address:");
gbc.gridwidth=1;
gbc.anchor=GridBagConstraints.WEST;
add(Address,gbc);
TextField AddrTextField=new TextField(25);
gbc.gridwidth=3;
add(AddrTextField,gbc);
Label City=new Label("City:");
gbc.gridwidth=1;
add(City,gbc);
TextField CityTextField=new TextField(15);
gbc.gridwidth=1;
add(CityTextField,gbc);
Label State=new Label("State:");
gbc.gridwidth=1;
add(State,gbc);
TextField StateTextField=new TextField(10);
gbc.gridwidth=1;
add(StateTextField,gbc);
Label PurchM=new Label("Purchase Method:");
gbc.gridwidth=1;
add(PurchM,gbc);
Choice Pay=new Choice();
Pay.add("VISA");
Pay.add("MasterCard");
Pay.add("COD");
gbc.gridwidth=3;
gbc.fill=GridBagConstraints.NONE;
add(Pay,gbc);
//Separator sep2=new Separator();
//gbc.gridwidth=GridBagConstraints.REMAINDER;
//gbc.fill=GridBagConstraints.BOTH;
//add(sep2);
Button PurchButton=new Button("Purchase");
gbc.gridwidth=2;
gbc.anchor=GridBagConstraints.CENTER;
gbc.fill=GridBagConstraints.NONE;
add(PurchButton,gbc);
Button Cancel=new Button("Cancel");
gbc.gridwidth=2;
gbc.anchor=GridBagConstraints.CENTER;
add(Cancel,gbc);
}
}
这里我想显示一个表单的布局,不过怎么显示也出不来,我不知道错在那里,那位高手能指点一下,最好能解释一下错在那里,谢谢了。:)
|
public void ButtonPurchForm()错误在这一行,构造函数是没有返回类型的,你给它加了
返回类型,就不是构造函数了
别的错误自己改吧
返回类型,就不是构造函数了
别的错误自己改吧