English 中文(简体)
我如何在油漆中使用图形2D,还是有更好的办法这样做?
原标题:How do I use graphics2D in paint or is there a better way to do this?

我想使用图形2D,但我不能让我展示我的图象。 是否有更好的途径来做到这一点,使我能够重新开始? 最后,我希望树立一个形象,作为背景,并能够利用这个形象,从而拯救框架的内容。

import java.awt.image.*;
import javax.imageio.ImageIO;
import javax.swing.*;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.swing.JApplet;
import java.awt.*;

// assume that the drawing area is 150 by 150
public class test extends JApplet
{
  final int radius = 25;
  int width = 200, height = 200;

 BufferedImage img = new BufferedImage(
   width, height, BufferedImage.TYPE_INT_ARGB);

  public void paint (  )
  { 
    Graphics2D g = img.createGraphics();
    g.setColor( Color.orange );
    g.fillRect( 0, 0, 150, 150 );
    g.setColor( Color.black );

    g.drawOval( (150/2 - radius), (150/2 - radius), radius*2, radius*2 );
   }
}
最佳回答

Oke

  1. 页: 1 你们需要一个图形物体。 <代码>公共真空油漆(Graphics g) 如同在你的切片开始时自动使用的缺省方法。

  2. 页: 1 当你需要使用您的缺席制图学标语,将其输入像Graphics2D g2d = (Graphics2D) g;

  3. 你们应当寻找更多关于双重缓冲的信息:

页: 1 这部法典正是从你想要的:

P.S 请注意我如何实施可操作性;如果你只想使用图表2D代码,你就不需要这样做。 这只是使该阶级成为一种read子,用于游戏标准:

这种希望有助于。

import java.applet.*;
import java.awt.*;


public class Test extends Applet implements Runnable{

public boolean isRunning = false;
public int radius = 25;


public void start() {
    isRunning = true;
    new Thread(this).start();
}

public void stop() {
    isRunning = false;
}

public void paint(Graphics g) {
    //Create Graphics2D object, cast g as a Graphics2D
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.ORANGE);
    g2d.fillRect(0, 0, 150, 150);

    g2d.setColor(Color.BLACK);
    g2d.drawOval((150/2 - radius), (150/2 - radius), radius * 2, radius * 2);
}

public void run() {

    while (isRunning) {
        repaint();
        try {
            Thread.sleep(17);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签