awt

Java and GUI - Where do ActionListeners belong according to MVC pattern?

淺唱寂寞╮ 提交于 2019-11-25 23:42:15
问题 I\'m currently writing a template Java application and somehow, I\'m not sure about where the ActionListeners belong if I wanted to cleanly follow the MVC pattern. The example is Swing based, but it\'s not about the framework but rather the basic concept of MVC in Java, using any framework to create GUI. I started with an absolutely simple application containing a JFrame and a JButton (to dispose the frame hence close the application). The code trailing this post. Nothing really special, just

What is the difference between Swing and AWT?

送分小仙女□ 提交于 2019-11-25 23:40:58
Can someone please explain me what's the difference between Swing and AWT? Are there any cases where AWT is more useful/advised to use than swing or vice-versa? skiphoppy AWT is a Java interface to native system GUI code present in your OS. It will not work the same on every system, although it tries. Swing is a more-or-less pure-Java GUI. It uses AWT to create an operating system window and then paints pictures of buttons, labels, text, checkboxes, etc., into that window and responds to all of your mouse-clicks, key entries, etc., deciding for itself what to do instead of letting the

SwingUtilities.invokeLater

£可爱£侵袭症+ 提交于 2019-11-25 23:22:39
问题 My question is related to SwingUtilities.invokeLater . When should I use it? Do I have to use each time I need to update the GUI components? What does it exactly do? Is there an alternative to it since it doesn\'t sound intuitive and adds seemingly unnecessary code? 回答1: Do I have to use each time I need to update the GUI components? No, not if you're already on the event dispatch thread (EDT) which is always the case when responding to user initiated events such as clicks and selections.

Collision detection with complex shapes

自作多情 提交于 2019-11-25 22:56:59
问题 I am wanting to make a game that has each level loaded from an image. I want to draw up the whole level in Photoshop, and then set it as the background and allow the player to walk over it. I want another invisible image to go over top which will be black in all places that I want to collide with. The reason I don\'t want to use tiles, which are much easier with rectangle collision and such, is because there will be complex corners and not everything will be rectangle. Is this a good idea,

Loading image resource

故事扮演 提交于 2019-11-25 22:53:56
问题 I am having a error for my GUI. Trying to set title bar icon then be included in a Runnable JAR. BufferedImage image = null; try { image = ImageIO.read(getClass().getClassLoader().getResource(\"resources/icon.gif\")); } catch (IOException e) { e.printStackTrace(); } frame.setIconImage(image); Here is the error I am getting: Exception in thread \"main\" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source) at GUI.<init>(GUI.java:39) at GUI.main(GUI

How to find a button source in AWT (calculator homework)

懵懂的女人 提交于 2019-11-25 22:20:16
问题 We were asked to make a simple GUI calculator, I used getSource() to detect the buttons, cause that\'s what they taught us. It works by typing the 1st and 2nd value then choosing the operation, it worked. But I made a mistake, because what they want us to do is that the numbers should also be buttons, just like a real calculator. so how do i get the value of each button using getSource()? like when I press button 1 and 2 is equal to 3. heres what ive done import java.awt.*; import java.awt

Calling awt Frame methods from subclass

妖精的绣舞 提交于 2019-11-25 22:13:17
问题 This question is about Frames, Java and Processing. This questions sounds pretty convoluted but its really not. I\'ll try keep this to a simple minimum. I\'m creating a small ball in a maze game to get my head around physics and rendering. It\'s been a good experience so far but I\'ve hit a bit of a brick wall. The general layout I decided on was to contain PApplets within a AWT Frame and have the Frame close. The reason for this is because I was told that you should only have on instance of

Java GUI listeners without AWT

醉酒当歌 提交于 2019-11-25 22:11:43
问题 I am a starting Java developer, learning just from internet tutorials. I am learning full screen GUI applications. I was told yesterday that I shouldn\'t use AWT in my programs, because it is outdated. I already know about light and heavyweight components, the main problem is the mouse and keyboard listeners. Why is AWT outdated? How to make a program without AWT (adding listeners to JComponents etc) (what kind of Swing things can replace the AWT)? 回答1: You're mis-interpreting the information

How to get X and Y index of element inside GridLayout?

元气小坏坏 提交于 2019-11-25 21:57:55
问题 I am studying a java tutorial and saw that the way to find the x/y indexes of a JButton inside a GridLayout is to traverse a bidimensional array of buttons b which is associated to the layout and checking if b[i][j] == buttonReference . @Override public void actionPerformed(ActionEvent ae) { JButton bx = (JButton) ae.getSource(); for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) if (b[i][j] == bx) { bx.setBackground(Color.RED); } } Is there an easier way to get the X/Y indexes of a