栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在JFrame中使用坐标平面

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在JFrame中使用坐标平面

Co-ordinates
TOP LEFT SIDE
屏幕的此处开始,随着的增加
X
,您将向前进
RIGHTSIDE
,而随着的增加
Y
,您将向前进
DOWNWARDS
。这是一个小的示例程序,您可以通过单击它的任意位置更好地理解它。

import java.awt.*;import java.awt.event.*;import javax.swing.*;public class DrawingExample{    private int x;    private int y;    private String text;    private Drawingbase canvas;    private void displayGUI()    {        Jframe frame = new Jframe("Drawing Example");        frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);        canvas = new Drawingbase();        canvas.addMouseListener(new MouseAdapter()        { public void mouseClicked(MouseEvent me) {     text = "X : " + me.getX() + " Y : " + me.getY();     x = me.getX();     y = me.getY();     canvas.setValues(text, x, y); }        });        frame.setContentPane(canvas);        frame.pack();        frame.setLocationByPlatform(true);        frame.setVisible(true);    }    public static void main(String... args)    {        SwingUtilities.invokeLater(new Runnable()        { public void run() {     new DrawingExample().displayGUI(); }        });    }}class Drawingbase extends JPanel{    private String clickedAt = "";    private int x = 0;    private int y = 0;    public void setValues(String text, int x, int y)    {        clickedAt = text;        this.x = x;        this.y = y;        repaint();    }    public Dimension getPreferredSize()    {        return (new Dimension(500, 400));    }    public void paintComponent(Graphics g)    {        super.paintComponent(g);        g.drawString(clickedAt, x, y);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/469866.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号