图形用户界面在Java中使用的Swing [英] GUI in Java using Swing

查看:195
本文介绍了图形用户界面在Java中使用的Swing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要就如何在Java中创建GUI一些指导。我在大学的一名学生,是的,他们从来不注重的事情之一。目前,我有我的计划的其余部分设置和工作,现在我试图使GUI。我创建这个新的GUI类。 (我是IM pression,这是我们的最佳做法下)。我有点了解如何进行基本设置,但我不明白如何与图形用户界面交互之后。我想要做的就是在启动一个窗口,然后并排显示两个画面一侧为每个下方的标签。我想要的图像,可以点击和点击时两个新的形象在他们的地方被加载(标签更改为下面)。我没有做过这样的事,我也已经跨越了很多不同的方法来添加图像跑了,我想知道如果有一个最好的做法。

I really need some guidance on how to create a GUI in Java. I'm a student in college and it's one of the the thing they never focus on. I currently have the rest of my program set up and working and now I'm trying to make the GUI. I'm creating a new GUI class for this. (I'm under the impression that this is the best practice for this). I kind of understand how to make the basic setup but I don't understand how to interact with the the GUI afterwards. What I want to do is make a window on startup and then it displays two pictures side by side with a label for each underneath. I want the images to be clickable and when clicked two new images are loaded in their place(labels are changed to underneath). I haven't done anything like this and I've also ran across a lot of different ways to add an image and I'm wondering if there is a best practice.

我可以提供code如果需要的话,但我不认为它会与我的问题是如何提出的需要。

I can provide code if needed but I didn't think it would be needed with how my question is posed.

在此先感谢所有帮助。

推荐答案

的几点建议:


  • 把你的图像到ImageIcons。请考虑ImageIcons的ArrayList

  • 显示在JLabel你ImageIcons。你可以通过调用的setIcon(...)更改图标。

  • 显示在同一个JLabel的文本(或如果你的愿望,图像的JLabel都是由一个BorderLayout的,使用的JPanel举行下持不同的JLabel)。通过它的setText更改文本的JLabel(...)方法。

  • 添加到MouseListener的图像持有的JLabel和改变听者的鼠标pressed方法JLabel的图标。你可以得到一个参考标签通过pssed的MouseEvent参数的的getSource()方法鼠标$ P $点击。

  • 在助理秘书长的评论中提到的教程将帮助你这一切。

编辑1:


  • 更妙的是 - 去与深褐色的下我的文章的评论推荐!

这篇关于图形用户界面在Java中使用的Swing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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