如何将其添加到我的Java小程序?

时间:2016-03-02 01:22:09

标签: java swing applet

这是一个我想添加到applet的简单类,但是我该怎么做呢?

这些是使用的变量:

int force = 1;
int distance = 50/force;
int x = distance*60;
int WIDTH = 300 - x;

这是绘画方法:

public void paint(Graphics g){
    g.setColor(Color.GRAY);
    g.drawString("Use the buttons to control the input force", 100, 25);
    g.fillRect(300, 250, 300, 25);
    g.fillRect(x, 250, WIDTH, 25);

如果我要更改这些按钮的位置,请告诉我。 (目前属于绘画方法)

    JButton subtract = new JButton("-");
    JButton add = new JButton("+");
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                force++;
            }

        });

    subtract.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            force--;
            }
        });
    add.setSize(50, 25);
    subtract.setSize(50, 25);
    if(force<=0){
        force =1 ;
    }
    add.setLocation(0,0);
    subtract.setLocation(51, 0);
    LApplet app = new LApplet();
    app.add(add);
    app.add(subtract);
    app.setBackground(Color.BLACK);
}}

0 个答案:

没有答案
相关问题