Java制作'点/像素'在swing / awt中 [英] Java making a 'dot/pixel' In swing/awt

查看:85
本文介绍了Java制作'点/像素'在swing / awt中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何在我的JFrame上的某个x,y坐标处制作点/像素。

I just want to know how to make a dot/pixel at a certain x,y co-ordinate on my JFrame.

任何人都知道一些简单的代码?

Anyone know some simple code for this?

谢谢,

推荐答案

我创建了一个小例子程序:

I have created a small example program:

public class Test extends JFrame {

    public Test() {
        this.setPreferredSize(new Dimension(400, 400));
        this.pack();
        this.setVisible(true);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);

        // define the position
        int locX = 200;
        int locY = 200;

        // draw a line (there is no drawPoint..)
        g.drawLine(locX, locY, locX, locY); 
    }

    public static void main(String[] args) {
        Test test = new Test(); 
    }
}

您还可以使用更新或paintComponents方法更好。但是你必须确保它被调用。如果您遇到问题并且没有被调用,您可以使用以下解决方案:为什么要涂漆()/ paintComponent()从未调用过?

You could also use the update or paintComponents method which would be much nicer. But then you have to make sure, that it gets called. If you have problems and it does not get called you could use the following solution: Why is paint()/paintComponent() never called?

这篇关于Java制作'点/像素'在swing / awt中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆