我需要用 Java 6 制作一个 640*480 像素的小程序,底部有一个工具栏,上面有一些按钮、滚动条和标签。我能想到的最好方法是使用 a BorderLayout
,使BorderLayout.SOUTH
区域 a GridBagLayout
(将包含控件)和BorderLayout
区域的其余部分为空,作为使用控件绘制图形的地方。我在网上找不到任何不使用swing的资源,而且我对swing一无所知以推断他们在做什么或如何将其翻译成awt代码。这就是我现在的位置。代码在 中突然结束init()
,因为这是布局管理器开始的地方。感谢您提供的任何帮助。如果您需要更多信息,请告诉我这里有什么。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Bounce extends Applet implements ActionListener, AdjustmentListener
{
private static final long serialVersionUID = 1L;
private Graphics page;
//buttons
String shapeButtonText = "Square";
Button shape = new Button(shapeButtonText);
Button quit = new Button("Quit");
Button run = new Button("Run");
Button tail = new Button("Tail");
Button clear = new Button("Clear");
//labels
Label speedLabel = new Label("Speed", Label.CENTER);
Label sizeLabel = new Label("Size", Label.CENTER);
//scrollbars
private final int barHeight = 20;
private final int SLIDER_WIDTH = 10;
private final int MAXSPEED = 110;
private final int MINSPEED = 0;
private final int UNIT_INC = 1;
private final int BLOC_INC = 10;
private final int MAX_SIZE = 110;
private final int MIN_SIZE = 10;
Scrollbar speedBar = new Scrollbar(Scrollbar.HORIZONTAL, MINSPEED, SLIDER_WIDTH, 0, MAXSPEED);
Scrollbar sizeBar = new Scrollbar(Scrollbar.HORIZONTAL, MIN_SIZE, SLIDER_WIDTH, 0, MAX_SIZE);
//methods
public void init()
{
//set up objects
//speed scroll bar
speedBar.setUnitIncrement(UNIT_INC);
speedBar.setBlockIncrement(BLOC_INC);
speedBar.setValue(MAXSPEED/2);
//size scrollbar
sizeBar.setUnitIncrement(UNIT_INC);
sizeBar.setBlockIncrement(BLOC_INC);
sizeBar.setValue(MAX_SIZE/2);
//draw the window
BorderLayout window = new BorderLayout();
GridBagLayout toolbar = new GridBagLayout();
//?
}
public void start()
{
}
public void run()
{
}
public void actionPerformed(ActionEvent e)
{
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
}
public void stop()
{
}
public void destory()
{
}
}