canvas 显示不全 java_Canvas对象未显示,但位置在Java Applet中正确更...

我的基本弹跳球Applet应该根据loc变量中的值移动一个球,但没有任何显示.打印出来的地方显示数字/数学背后移动它并反弹边界确实正常工作,但没有任何显示.在线查看示例我不明白为什么我的绘图/绘图代码没有按预期工作.这就是我所拥有的,问题可能集中在Ball对象的中间位置.我发布了大部分程序,因为如果有人会运行它,它会编译/运行.

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class Bounce2 extends Applet implements ActionListener, AdjustmentListener, Runnable

{

//runtime variables

boolean running = false;

boolean kill = false;

//buttons

Button runbutton = new Button("Run");

Button pausebutton = new Button("Pause");

Button quitbutton = new Button("Quit");

//text

Label speedlabel = new Label("Speed");

Label sizelabel = new Label("Size");

//scrollbars

private final int barHeight = 20, SLIDER_WIDTH = 10, MAXSPEED = 110, MINSPEED = 0, MAX_SIZE = 110, MIN_SIZE = 10;

Scrollbar speedbar = new Scrollbar(Scrollbar.HORIZONTAL, MAXSPEED/2, SLIDER_WIDTH, MINSPEED, MAXSPEED);

Scrollbar sizebar = new Scrollbar(Scrollbar.HORIZONTAL, MAX_SIZE/2, SLIDER_WIDTH, MIN_SIZE, MAX_SIZE);

//drawn objs

Ball ball;

int size = 50;

private Graphics obj;

Image offscreen = null;

Point loc = new Point(100,100); //location of the ball

private Thread ballThread;

//boundaries

int boundx = 640;

int boundy = 400;

//directions

int dx = 1; //1 = left, -1 = right

int dy = 1; //1 = up, -1 = down

//speed

int speed = speedbar.getValue();

int delay;

//initialize the applet and draw everything

public void init()

{

double colWeight[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};//15 cols

double rowWeight[] = {1,1,1,1,1,1,1,1,1,1}; //10 rows

int colWidth[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};//15 cols

int rowHeight[] = {1,1,1,1,1,1,1,1,1,1}; //10 rows

GridBagConstraints c = new GridBagConstraints();

GridBagLayout gbl = new GridBagLayout();

gbl.rowHeights = rowHeight;

gbl.rowWeights = rowWeight;

gbl.columnWeights = colWeight;

gbl.columnWidths = colWidth;

c.anchor = GridBagConstraints.CENTER;

setBounds(0,0,480,640);

setLayout(new BorderLayout());

Panel controlpanel = new Panel();

controlpanel.setLayout(gbl);

controlpanel.setSize(640,80);

Panel drawingpanel = new Panel(null);

drawingpanel.setSize(640,400);

ball = new Ball();

drawingpanel.add(ball);

drawingpanel.setVisible(true);

//speed scrollbar

c.weightx = 1;

c.weighty = 1;

c.gridwidth = 3;

c.gridheight = 1;

c.gridx = 1;

c.gridy = 7;

c.fill= GridBagConstraints.HORIZONTAL;

gbl.setConstraints(this.speedbar,c);

//run button

c.weightx = 1;

c.weighty = 1;

c.gridwidth = 2;

c.gridheight = 1;

c.gridx = 5;

c.gridy = 7;

c.fill= GridBagConstraints.HORIZONTAL;

gbl.setConstraints(this.runbutton,c);

//pause button

c.weightx = 1;

c.weighty = 1;

c.gridwidth = 2;

c.gridheight = 1;

c.gridx = 8;

c.gridy = 7;

c.fill= GridBagConstraints.HORIZONTAL;

gbl.setConstraints(this.pausebutton,c);

//size scrollbar

c.weightx = 1;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值