1
왜 이렇게하면 아래쪽과 오른쪽이 렌더링되지 않습니다. 어떻게 수정해야합니까? 아무 것도 그려지지 않는 작은 흰색 영역이 있습니까? 이 문제에 대한 간단한 수정이있을 것이라고 확신하지만 너무 어리 석다.자바 그래픽이 아래쪽과 오른쪽에 페인팅되지 않습니다.
필자는 불필요한 부분은 없지만 일부 무작위 코드는 여전히 남아있을 수 있습니다.
package test;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test extends JPanel implements Runnable
{
/**
* Default serial version
*/
private static final long serialVersionUID = 1L;
private static final int WIN_WIDTH = 760;
private static final int WIN_HEIGHT = 480;
private boolean running;
private Thread thread;
public Graphics g;
public Graphics2D g2d;
static final int UPDATE_RATE = 60;
static final long UPDATE_PERIOD = 1000000000L/UPDATE_RATE;
static public final int EONWIDTH = 24;
static public final int EONHEIGHT = 24;
/**
* Contains a list of Eon instances by their instance ID.
*/
///////////////////////////////////CONSTRUCTER/////////////////////////////
public Test()
{
Dimension size = new Dimension(WIN_WIDTH, WIN_HEIGHT);
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
}
/**
* Main java runnable, required
* @param args Unused, required by default
*/
public static void main(String[] args)
{
Test game = new Test();
JFrame frame = new JFrame("See guys, It's off centered... - 00.00.10");
JPanel panel = new JPanel(new BorderLayout());
panel.add(game, BorderLayout.CENTER);
frame.setContentPane(panel);
frame.pack();
frame.isFocusable();
frame.setFocusable(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
game.g = game.getGraphics();
game.start(game);
}
private void loopUpdate(Test game)
{
game.repaint();
}
boolean done = true;
public void paint(Graphics g)
{
System.out.print(g.getClipBounds().width + ", " + g.getClipBounds().height + "\n");
super.paint(g);
g.setClip(0,0, WIN_WIDTH, WIN_HEIGHT);
final Graphics2D g2d = (Graphics2D) g;
if (done)
{
done=false;
try
{
g2d.fillRect(0, 0, WIN_WIDTH + 100, WIN_HEIGHT + 100);
} catch (Exception e) {
e.printStackTrace();
}
g.dispose();
done = true;
}
}
@Override
public void run()
{
loopUpdate(this);
}
}
하시기 바랍니다. 나는 거의 모든 사람들이이 문제를 해결할 수있는 방법을 알고 있으므로 제발 누군가 나를 도와 줄 수 있다는 것을 알고 있습니다.
문제를 설명하는 [sscce] (http://sscce.org/)를 포함하여 질문을 편집하십시오. – trashgod
@trashgod 죄송합니다. –
당신은 큰소리하지 않아도됩니다. +1 (가까운) [sscce] (http://sscce.org/). – trashgod