java - JApplet 幻灯片中的公共空白绘制(图形 g)错误
问题描述
我正在尝试在 JApplet 中制作幻灯片,但在“public void paint (Graphics g)'s”上不断出现错误。我知道它已经过时了,但它适用于高中的课程。这是我第一次这样做,所以如果这是一个愚蠢的问题,请原谅。该项目只是在文本和图像周围有一个带有黄色框的图像。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class timers extends JApplet implements ActionListener
{
Timer timer1;
int seconds = 1;
Image picture1;
Image picture2;
Image picture3;
Image picture4;
Image picture5;
public void init ()
{
// set applet size
setSize (800, 600);
//constructor Timer(int millidelay, ActionListener l)
timer1 = new Timer (1000, this);
picture1 = getImage (getDocumentBase (), "Red_Color.jpeg");
picture2 = getImage (getDocumentBase (), "Color-blue.jpeg");
picture3 = getImage (getDocumentBase (), "Color-yellow.jpeg");
picture4 = getImage (getDocumentBase (), "green.png");
picture5 = getImage (getDocumentBase (), "pink.jpeg");
//
repaint ();
}
public void start ()
{
timer1.start ();
}
public void stop ()
{
timer1.stop ();
}
public void destroy ()
{
//System.exit(0);
}
public void paint (Graphics g)
{
g.setColor (Color.BLACK);
g.fillRect (0, 0, 800, 600);
g.setFont (new Font ("Helvetica", Font.PLAIN, 20));
g.setColor (Color.yellow);
g.drawString ("This is the colour red", 270, 473);
g.drawImage (picture1, 300, 200, 200, 200, this);
g.setColor (Color.yellow);
g.drawRect (275, 175, 251, 251);
g.drawRect (269, 445, 265, 40);
} // end of paint
public void paint (Graphics g)
{
g.setColor (Color.BLACK);
g.fillRect (0, 0, 800, 600);
g.setFont (new Font ("Helvetica", Font.PLAIN, 20));
g.setColor (Color.yellow);
g.drawString ("This is the colour blue", 270, 473);
g.drawImage (picture2, 300, 200, 200, 200, this);
g.setColor (Color.yellow);
g.drawRect (275, 175, 251, 251);
g.drawRect (269, 445, 265, 40);
}
public void actionPerformed (ActionEvent e)
{
if (e.getSource () == timer1)
// timer is firing
// increment second counter
seconds++;
//call paint method
repaint ();
}
}
解决方案
推荐阅读
- android - 为 Google Play 多人游戏创建不同的房间
- google-cloud-platform - 子文件夹的 GCS 对象更改通知
- python - 是否有可能获得 Spacy 命名实体识别的置信度分数
- angular - 我应该使用 null 作为数字的值吗 - Angular
- node.js - 如何在nodejs中promise类型的函数中完成.map函数后返回对象
- php - 调用Factory时Laravel记录被删除
- ios - 在主对象选择之前隐藏底部标签栏
- react-native - 路由“x”的组件必须是 React 组件
- reactjs - 在尝试部署到 heroku 时找不到文件(在本地工作)
- javascript - 用于 iOS 构建的多个 Unity 场景脚本