任何想法如何解决此警告?我对此一无所知,所以有什么可以帮助的。我遵循macheads101的教程,其中涉及GUI,请链接到https://www.youtube.com/watch?v=p9Y-NBg8eto&list=PL3A1hYAjJF0ex144ovCjh8Wd3v0j7sgd_&index=12。
//not full code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
//@SuppressWarnings("serial")
public class snakeMovement extends JPanel implements ActionListener,KeyListener
{
Timer t = new Timer(5, this);
double x = 400, y = 400, velx = 0, vely = 0;
public snakeMovement()
{
this.setSize(40, 40);
t.start();
addKeyListener(this);
setFocusable(true);
setFocusTraversalKeysEnabled(false);
}
public void paintComponenet(Graphics g)
{
System.out.println("it made it");
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
Rectangle2D head = new Rectangle2D.Double(x, y, 40, 40);
g2.fill(head);
g2.setPaint(Color.RED);
}
public void actionPerformed(ActionEvent e)
{
repaint();
if(x < 0 || x > 760)
{
velx = 0;
}
else if(y < 0 || y > 760)
{
vely = 0;
}
else
{
x += velx;
y += vely;
}
}