「java界面gui」JAVA界面设计

博主:adminadmin 2023-03-20 00:52:09 498

今天给各位分享java界面gui的知识,其中也会对JAVA界面设计进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

JAVA图形界面(GUI)为什么现在很少有人用

最佳答案

原因(个人意见)

系统没有集成java类库,开发出来的界面还需要加入几十M库,导致安装包非常的大,用户不能接受而已。(可能实现功能的代码不足1M,而库就需要30M)如果操作系统自带了部分库,可能会好一点

开发出精美的界面需要自己重构的组件太多,费力不讨好的事情。自带的组件都比较丑陋,相当于你在开发库

部分性能不如C或C++,Java是轻量级的,现在都是网络时代,如果你开发的软件只能玩单机就没有意思了,如:做一个屏幕控制软件,一般的思路就是截屏发送屏幕,发送相应的响应操作。发送就需要通信你用java 自带的通信 TCP UDP 什么的 麻烦并且性能永远都跟不上

学习是可以的,写点小应用玩,还是很不错的。如:记事本、计算器、五子棋等

有实现java自动生成GUI界面的工具

目前JAVA图形界面开发主流工具如下:

1. WindowBuilder Pro

2. Jigloo(最新版是2010年更新的,看来这个项目现在已经不再做了)

3. 也可以直接用IDE如:NetBeans或MyEclipse,二者中都有自带的图形开发拖拽工具

相关阅读:

Eclipse进行可视化的GUI开发3大GUI插件

java图形界面(GUI)

import java.awt.*;

import java.awt.event.*;

import java.util.Random;

public class Window extends Frame{

Button button1 = new Button("开始");

Button button2 = new Button("结束");

TextField textfield = new TextField();

static Random random = new Random();

String string = null;

boolean bstart = false;

Thread thread;

public void launchFrame() {

this.setLocation(500, 200);

this.setLayout(new BorderLayout());

this.add(button1, new BorderLayout().WEST);

this.add(button2, new BorderLayout().EAST);

this.add(textfield, new BorderLayout().NORTH);

button1.addActionListener(new Button1Listener());

button2.addActionListener(new Button2Listener());

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

pack();

setVisible(true);

}

private class Button1Listener implements ActionListener {

public void actionPerformed(ActionEvent e) {

bstart = true;

thread = new Thread(new NumProduce());

thread.start();

}

}

private class Button2Listener implements ActionListener {

public void actionPerformed(ActionEvent e) {

bstart = false;

}

}

private class NumProduce implements Runnable {

private void numproduce() {

string = Integer.toString(random.nextInt()); /*nextint的括号中处可以修改产生随机数的范围*/

textfield.setText(string);

}

public void run() {

while(bstart) {

try {

numproduce();

Thread.sleep(50);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

public static void main(String[] args) {

new Window().launchFrame();

}

}

java中GUI是什么意思啊解释一下

常常用Controler来表示,一个类.

一般初学的时候,都是在一个监听接口的方法实现中对某另一个类进行操作.

比如一点地址栏的回车,下面的状态栏会显示IP地址等.

按照面向对象的发消息机制,有控制模块的程序不再是直接对其他类进行操作,而是在触发事件的时候向控制模块发消息,由控制模块启动相应类的进程,向其发消息,以改变其状态.这样一来各个组件之间不必互相认识,只要通过控制中心联系就可以了.

例如上面那个例子,点完回车后,地址栏的向控制器发一个消息,控制器启动响应的状态栏对象的进程,再向其发送一个消息,使其调用自身的改变状态方法.

如何进行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(); //傻B

}

}

JAVA程序设计,使用GUI界面

效果图

参考代码

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class KeyFrame extends JFrame implements KeyListener{

JLabel jlkey;

public KeyFrame() {

jlkey = new JLabel("请输入字母或者数字,其他字符不显示");

add(jlkey);

addKeyListener(this);

setLayout(new FlowLayout());

setSize(260, 160);

setTitle("输入...");

setLocationRelativeTo(null);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

}

public static void main(String[] args) {

new KeyFrame();

}

public void keyTyped(KeyEvent e) {//敲击键盘

c=e.getKeyChar();//得到键入的字符

repaint();//重绘

}

public void keyPressed(KeyEvent e) {//按下键盘

// c=e.getKeyChar();

// repaint();

}

public void keyReleased(KeyEvent e) {//释放键盘

}

char c ;

@Override

public void paint(Graphics g) {

super.paint(g);

//如果只能显示输入的是字母或者数字,那么需要if判断下

if((c='Z' c='A')||(c='z'c='a')||(c='9'c='0')){// 注意比较的是字符 '9' 和字符'0'

Font font = g.getFont();

g.setColor(Color.BLUE);

g.setFont(new Font(font.getName(),font.getStyle(),20));

g.drawString(c+"",100, 100); //绘制

}

}

}

关于java界面gui和JAVA界面设计的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。