导航:首页 > 编程语言 > java中gui编程

java中gui编程

发布时间:2022-09-10 20:07:53

java gui图形界面编程键盘输入字母转换大小写

从键盘输入一个小写字母,然后输入出对应的大写字母,用两种输入输入的方法实现。第一种使用控制输入输出,第二种是使用对话框输入输出。这样即可实现javagui图形界面编程键盘输入字母转换大小写。

❷ Java GUI编程

我做了下修改,你运行一下看看。另外还有点小问题,不过我没时间修改了,去忙了。

importjava.awt.Color;
importjava.awt.Dimension;
importjava.awt.Graphics;
importjavax.swing.JComponent;

{

privateintx;
privateinty;
privatefinalbooleanRIGHT=true;
//privatefinalbooleanLEFT=false;

privatebooleandirection;

publicMovingComponent()
{
x=0;
y=0;
direction=RIGHT;
}
publicintgetX(){
returnx;
}
publicvoidreverse(){
direction=!direction;
}

publicvoidpaintComponent(Graphicsg)
{
g.setColor(Color.GREEN);
g.fillRect(x,y,100,100);
}

publicvoidmove()
{
intwidth=getWidth();
if(direction){
x=x+2;

}else{
x=x-2;
}
repaint();
}
}

importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;

importjavax.swing.JFrame;
importjavax.swing.Timer;

{

privateMovingComponentbox;

publicMovingFrame()
{
box=newMovingComponent();
add(box);
setSize(800,600);

TimerListenerlistener=newTimerListener();
Timert=newTimer(10,listener);
t.start();

}


{
@Override
publicvoidactionPerformed(ActionEventevent){
if((box.getX()*2+100>getWidth())||(box.getX()<0)){
//上面为什么要乘以2,说实话,我暂时没想明白
box.reverse();
}
System.out.println(box.getX()+""+getWidth());
box.move();
}
}
}importjavax.swing.JFrame;

publicclassMovingTester{

publicstaticvoidmain(Stringargs[])
{
JFrameframe=newMovingFrame();

frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("MovingBox!");
}
}

❸ java的GUI编程,如何关闭一个窗体,而不是退出整个程序

JFrame的关闭不像Frame,点关闭按钮自己会关闭,但是那样做不好.可以用setDefaultCloseOperation(int operation);
其中operation有以下几种
DO_NOTHING_ON_CLOSE(在 WindowConstants 中定义):不执行任何操作;要求程序在已注册的 WindowListener 对象的 windowClosing 方法中处理该操作。
HIDE_ON_CLOSE(在 WindowConstants 中定义):调用任意已注册的 WindowListener 对象后自动隐藏该窗体。
DISPOSE_ON_CLOSE(在 WindowConstants 中定义):调用任意已注册 WindowListener 的对象后自动隐藏并释放该窗体。
EXIT_ON_CLOSE(在 JFrame 中定义):使用 System exit 方法退出应用程序。仅在应用程序中使用。
默认情况下,该值被设置为 HIDE_ON_CLOSE。更改此属性的值将导致激发属性更改事件,其属性名称为 "defaultCloseOperation"。

❹ java的gui编程,高手来救啊

监听的目前没有啥好的想法
关于按键的有点,给你分享一下,理解不对的话,见谅啊。

你的问题现在是,先按住上方向键,坦克向上走,按住上键,又按住左键了,坦克向左走,此时放开左键了,坦克没有继续向上走,而需要你重新按向上键。

如果我理解对了,你继续看,不对就算了、、、
如果是上面的问题,你程序的处理应该是监听到Key按下事件,然后根据Key的值,向不同的方向移动,监听到Key放开事件,就停止移动

如果想继续移动,可以通过程序去判断:
1:在监听类,中定义一个Map<Integer> 保存按下的Key
2:监听到Key按下事件,把Key保存到Map中,并向改方向移动。
3:监听到Key放开事件,把Key从Map中移除,并判断Map是否为空,为空停止移动,如果不为空,获取Map中的Key值,继续向Key所指向方向移动

注:这个方法只支持最多按两个键,多了的话,比如现在按住3个键,放开一个了,不处理的话,因为Map不是排序的,随便获取一个Key的话,移动的方向可能不是自己想要的,如果要支持多键的,可以使用LinkedMap,他可以保存按键的保存顺序,比如按键的顺序为a,b,c 放开c的时候,迭代Map,第一个一定是b,你可以向b方向移动,放开b的时候,迭代Map,获取就是a了

❺ java gui编程基础

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Max extends JFrame implements ActionListener{
//JFrame MaxFrame;
JTextField a;
JTextField b;
JTextField c;
JTextField d;

JButton BAd;
double maxc = 0;
int max= 0;
public Max (){
this.setBounds(300,300,300,200);
this.setVisible(true);
// MaxFrame = new JFrame("MaxFrame");
a = new JTextField("0.0");
b = new JTextField("0.0");
c = new JTextField("0.0");
BAd = new JButton("最大数");
d = new JTextField("0.0");
BAd.addActionListener(this);
this.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,5,20));
this.getContentPane().add(a);
this.getContentPane().add(b);
this.getContentPane().add(c);
this.getContentPane().add(BAd);
this.getContentPane().add(d);

this.pack();
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent event){

if (Double.valueOf(a.getText()).doubleValue() >Double.valueOf(b.getText()).doubleValue())

maxc = (Double.valueOf(a.getText()).doubleValue());
else maxc = (Double.valueOf(b.getText()).doubleValue());

if (maxc < Double.valueOf(c.getText()).doubleValue())

maxc = (Double.valueOf(c.getText()).doubleValue());
max = (int) maxc;
d.setText("" + max);

}
public static void main(String[] args){
new Max ();
}
}
//把满意答案给楼上的那位

❻ 如何进行Java GUI图形用户界面编程

在远标做过直接使用javax.swing和java.awt两个包
一个简单的GUI程序如下:
packagesix;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
publicclassMain extendsJFrame{ //类Main继承自JFrame
privateJPanel pane = null;
privateJPanel p = null;
privateCardLayout card = null;
privateJButton button_1 = null;
privateJButton button_2 = null;
privateJButton b1 = null,b2 = null,b3 = null;
privateJPanel p1 = null,p2 = null,p3 = null;
publicMain() //
{
super("卡片布局管理器测试");
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception ex){
ex.printStackTrace();
}
//创建新卡片布局
card = newCardLayout(5,5);
pane = newJPanel(card);
p = newJPanel();
button_1 = newJButton("< 上一步");
button_2 = newJButton("下一步 >");
b1 = newJButton("1");b2 = newJButton("2");b3 = newJButton("3");
b1.setMargin(newInsets(2,2,2,2));
b2.setMargin(newInsets(2,2,2,2));
b3.setMargin(newInsets(2,2,2,2));
p.add(button_1);p.add(b1);p.add(b2);p.add(b3);p.add(button_2);
p1 = newJPanel();
p2 = newJPanel();
p3 = newJPanel();
p1.setBackground(Color.RED);
p2.setBackground(Color.BLUE);
p3.setBackground(Color.GREEN);
p1.add(newJLabel("JPanel_1"));
p2.add(newJLabel("JPanel_2"));
p3.add(newJLabel("JPanel_3"));
pane.add(p1,"p1");pane.add(p2,"p2");pane.add(p3,"p3");
//翻转卡片布局动作
button_1.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvent e){
card.previous(pane);
}
});
button_2.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvent e){
card.next(pane);
}
});
b1.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvent e){
card.show(pane, "p1");
}
});
b2.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvent e){
card.show(pane,"p2");
}
});
b3.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvent e){
card.show(pane, "p3");
}
});
this.getContentPane().add(pane);
this.getContentPane().add(p,BorderLayout.SOUTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 200);
this.setVisible(true);
}
publicstaticvoidmain(String[]args)
{
newMain(); //
}
}

❼ java中gui编程使用的多么

个人理解:gui编程,主要是图形化界面加上事件的处理,说实话,我感觉用的不多,不过主要是了解gui编程的思想,像他里面的回调机制,匿名内部类。。。

❽ 简单的GUI编程java编写

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JOptionPane;

public class TestGUI extends Frame{
private TextField tf = null;
private Button btn = null;

public static void main(String[] args) {
new TestGUI().init();
}

public void init() {
//窗口关闭事件
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setLayout(new FlowLayout());
tf = new TextField(15);
btn = new Button("计算");
//按键响应事件
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String s = "你输入字符的个数为:" + tf.getText().length();
//弹窗显示结果
JOptionPane.showMessageDialog(null,s);
}
});
add(tf);
add(btn);
setBounds(400, 300, 400, 300); //设置窗体的位置和尺寸
setVisible(true);
}
}

❾ JAVA的GUI编程是不是很重要

不是 其实初学学JAVA不太好 因为太容易 没有C++那种底层的东西 JAVA在GUI方面和C++ VB不能比 JAVA真正擅长的是在服务器方面 学习JAVA一定要把重点放在服务器编程这块

❿ Java实现GUI编程基本方法都有那些

典型的包括窗口(Window)、框架(Frame/JFrame)、对话框(Dialog/JDialog)、面板(Panel/JPanel)等。只有先创建了这些容器,其它界面元素如按钮(Button/JButton)、标签(Label/JLabel)、文本框(TextField/JTextField)等才有地方放。
②添加组件
为了实现GUI应用程序的功能,为了与用户交换,需要在容器上添加各种组件/控件。这需要根据具体的功能要求来决定用什么组件。例如,如果需要提示信息,可用标签(Label/JLabel);如果需要输入少量文本,可用文本框(TextField/JTextField);如果需要输入较多文本,可用文本区域(TextArea/JTextArea);如果需要输入密码,可用密码域(JPasswordField)等等。
③安排组件
与传统的Windows环境下的GUI软件开发工具不同,为了更好地实现跨平台,Java程序中各组件的位置、大小一般不是以绝对量来衡量,而是以相对量来衡量。例如有时候,程序的组件的位置是按"东/East"、"西/West"、"南/South"、"北/North"、"中 /Center"这种方位来标识的。因此,在组织界面时,除了要考虑所需的组件种类外,还需要考虑如何安排这些组件的位置与大小。这一般是通过设置布局管理器(Layout Manager)及其相关属性来实现的。事实上上述按方位来安排组件就是采用了Java中多种布局管理器里的BorderLayout布局管理器。
为了完成一个GUI应用程序所应具备的功能,除了适当地安排各种组件产生美观的界面外,还需要处理各种界面元素事件,以便真正实现与用户的交换,完成程序的功能。在Java程序中这一般是通过实现适当的事件监听者接口来完成的。

阅读全文

与java中gui编程相关的资料

热点内容
编译动态库时会连接依赖库吗 浏览:706
淘宝手机加密是随机的吗 浏览:672
解压包子怎么装饰 浏览:585
四个数凑24算法 浏览:676
哪一种不是vi编译器的模式 浏览:168
xp在此处打开命令窗口 浏览:128
代码编译运行用什么软件 浏览:997
动态库在程序编译时会被连接到 浏览:760
python超简单编程 浏览:259
获取命令方 浏览:976
怎样制作文件夹和图片 浏览:59
调研编译写信息 浏览:861
python冯诺依曼 浏览:419
同时安装多个app有什么影响 浏览:254
奥术杀戮命令宏 浏览:184
用sdes加密明文字母e 浏览:361
单片机原理及应用试题 浏览:425
易语言开启指定文件夹 浏览:40
马思纯参加密室大逃脱 浏览:322
文件夹冬季浇筑温度 浏览:712