我在使用JAVA进行编码时遇到了一些错误,我一直在尝试修复此问题,同时也试图找到有相同问题的oterh ppl并修复它但没有任何工作......
嗯..这是代码
package ca.vanzeben.game;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable {
private static final long serialVerisionUID = 1L;
public static final int WIDTH = 160;
public static final int HEIGHT = WIDTH / 12*9;
public static final int SCALE = 3;
public static final String NAME = "Game";
public boolean running = false;
public int tickCount = 0;
private JFrame …Run Code Online (Sandbox Code Playgroud) 我正在编写一个类似炸弹人的游戏,但我的 KeyListener 有问题。
\n\n问题是,当游戏运行时,KeyListener 不会响应,但是当它不运行时,它会执行我告诉他的操作。
\n\n这是我的代码
\n\npublic class direction extends Canvas implements KeyListener {\n\nstatic float bmx = 35;\nstatic float bmy = 35;\nstatic float v = 0.03f;\n\npublic static BufferStrategy strategie;\npublic static BufferedImage image;\n\npublic direction() { //pas s\xc3\xbbr de ce que \xc3\xa7a fait\n GraphicsEnvironment ge = //on m\'a dit de le mettre \n GraphicsEnvironment.getLocalGraphicsEnvironment(); //le programme marche tr\xc3\xa8s bien sans\n GraphicsDevice gd = ge.getDefaultScreenDevice();\n GraphicsConfiguration gc = gd.getDefaultConfiguration();\n image = gc.createCompatibleImage(700, 700);\n setSize(700, 700);\n\n}\n\n static boolean gauche;\n static boolean …Run Code Online (Sandbox Code Playgroud) 有什么方法可以在画布上添加jlabel吗?在我的代码中,我的框架的构造函数在添加画布之前首先添加标签但是当我运行它时它不显示标签.
我画的画布背景.
我想画一个可以在 Jpanel 上移动的画布。那就是当用户点击画布并拖动它时,它必须移动到一个新的位置。我已经实现了 MouseMotionListener 但我不知道在里面包含什么来使画布按照要求移动。这是 DisplayCanvas 类:
class DisplayCanvas extends Canvas
{
public DisplayCanvas()
{
setBounds(20, 40, 300, 300);
setBackground(Color.white);
}
}
class shape extends JFrame implements MouseMotionListener{
static JPanel panel;
static Container contentpane;
static DisplayCanvas canvas;
shape()
{
canvas=new DisplayCanvas();
canvas.addMouseMotionListener(this);
panel= new JPanel();
panel.setBounds(20,20,250,140);
panel.setLayout(null);
contentpane = getContentPane();
contentpane.add(canvas);
contentpane.add(panel);
}
@Override
public void mouseDragged(MouseEvent e) {}
@Override
public void mouseMoved(MouseEvent arg0) {}
}
Run Code Online (Sandbox Code Playgroud)
这就是我测试它的方式。
public class display
{
static JFrame frame;
public static void main(String[] args)
{ …Run Code Online (Sandbox Code Playgroud) java ×4
java-canvas ×4
swing ×4
awt ×1
image ×1
jlabel ×1
jpanel ×1
key-bindings ×1
keylistener ×1