日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

往java里输入坐标值_java.让用户输入x坐标,和y坐标。当用户输入完x坐标(比如200),敲enter,...

發布時間:2024/7/5 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 往java里输入坐标值_java.让用户输入x坐标,和y坐标。当用户输入完x坐标(比如200),敲enter,... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

展開全部

import?java.awt.event.ActionEvent;

import?java.awt.event.ActionListener;

import?javax.swing.JButton;

import?javax.swing.JFrame;

import?javax.swing.JLabel;

import?javax.swing.JTextField;

import?javax.swing.SwingConstants;

public?class?SetLocationFrame?extends?JFrame{

private?JTextField?t1,t2;

JLabel?l;

int?x,y;

public?static?void?main(String[]args){

62616964757a686964616fe4b893e5b19e31333332633039new?SetLocationFrame();

}

public?SetLocationFrame(){

super("Where?should?I?be?");

this.setLayout(null);

this.setDefaultCloseOperation(3);

init();

this.setVisible(true);

}

private?void?init()?{

setBounds(100,?100,?300,?200);

x?=?this.getLocation().x;

y?=?this.getLocation().y;

JLabel?lblNewLabel?=?new?JLabel("Enter?new?X?here");

lblNewLabel.setBounds(44,?10,?136,?20);

add(lblNewLabel);

JLabel?lblEnterNewY?=?new?JLabel("Enter?new?Y?here");

lblEnterNewY.setBounds(44,?40,?136,?20);

add(lblEnterNewY);

t1?=?new?JTextField(x+"");

t1.setBounds(190,?10,?66,?21);

add(t1);

t1.setColumns(10);

t1.addActionListener(new?ActionListener(){

@Override

public?void?actionPerformed(ActionEvent?e)?{

x?=?Integer.parseInt(t1.getText());

l.setText("x?is?"+?x?+"?and?y?is?"+y);

t2.requestFocus();

}

});

t2?=?new?JTextField(y+"");

t2.setColumns(10);

t2.setBounds(190,?40,?66,?21);

add(t2);

t2.addActionListener(new?ActionListener(){

@Override

public?void?actionPerformed(ActionEvent?e)?{

y?=?Integer.parseInt(t2.getText());

l.setText("x?is?"+?x?+"?and?y?is?"+y);

}

});

JButton?b?=?new?JButton("Move?The?Window");

b.addActionListener(new?ActionListener()?{

@Override

public?void?actionPerformed(ActionEvent?e)?{

setLocation(x,y);

System.out.println(x?+":"?+?y);

}

});

b.setBounds(54,?70,?197,?37);

add(b);

JLabel?lblComponentOfCurrent?=?new?JLabel("Component?of?Current?Location:");

lblComponentOfCurrent.setBounds(44,?114,?197,?20);

add(lblComponentOfCurrent);

l?=?new?JLabel("x?is?"+?x?+"?and?y?is?"+y);

l.setHorizontalAlignment(SwingConstants.CENTER);

l.setBounds(64,?144,?156,?20);

add(l);

}

}

總結

以上是生活随笔為你收集整理的往java里输入坐标值_java.让用户输入x坐标,和y坐标。当用户输入完x坐标(比如200),敲enter,...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。