awt

Could someone explain what purpose EventQueue object serves?

雨燕双飞 提交于 2019-12-12 03:04:24
问题 Could someone explain what purpose EventQueue object serves in Java Swing? I'm mostly confused about how queuing events is applied. Maybe providing common use of an event queue would be helpful. 回答1: Because Swing is single threaded, it uses the EventQueue to hold instances of Runnable so that they can be dispatched sequentially and in the order posted , whether generated by the system or your program. The sine qua non usage is posting an event via EventQueue.invokeLater() , which ensures

How to move JFrame shape

冷暖自知 提交于 2019-12-12 02:58:28
问题 I'm trying to develop a simple game. The games is about the shapes. Shapes will move and we'll catch by mouse. I have already created a oval and given size of oval graphic. But I cannot move this shape repeatedly. I think I need to use timer class. I have been trying 2 hours myself but I didnt do yet. The code; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import

Collision detection with complex shapes

别来无恙 提交于 2019-12-12 02:57:18
问题 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, and

Why is my eclipse not setting my background color?

我的梦境 提交于 2019-12-12 02:44:06
问题 I have designed a code for a game. The problem is that the background won't change to any of my selected colors I have picked from graphics color library. I need someone to figure this out with the code i have provided (please don't make a whole new code). idk why java/ eclipse won't display it??? am i missing something?? The program here should display a GUI with a background color blue. instead i get white. public class MainApp extends Canvas implements Runnable { private static final long

Java CheckboxMenuItem get/setState

久未见 提交于 2019-12-12 02:16:17
问题 I am using this to create a quick menu in my Java system tray app. Menu notiSET = new Menu("Benachrichtigungen"); CheckboxMenuItem ns1 = new CheckboxMenuItem("On"); CheckboxMenuItem ns2 = new CheckboxMenuItem("Off"); I would like to set Checkbox ns1 to true by default. Using ns1.setState(true); doesnt work - I can only change the state by clicking it. I tried using .setSelected(); or isSelected(); which doesnt work as well (methods not known). What am I doing wrong? 回答1: Your menu items live

How to randomly set a JFrame with a simple message

孤街醉人 提交于 2019-12-12 02:12:14
问题 So I've checked out the other post which didn't help on here, I'm trying to get my frame with it's message to randomly appear on an area on the screen but when I run it, it says x and y cannot be resolved to a variable, here's the code: public class MyFrame extends JFrame{ MyFrame(int width, int height, int x, int y){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("R and Ts Main Frame"); setSize(width, height); Random random = new Random(); x = random.nextInt(); y = random.nextInt()

How can I get the location of the mouse pointer in a JPanel (Without any operation of the Mouse)?

痞子三分冷 提交于 2019-12-12 02:07:05
问题 I can get the mouse pointer location in a JPanel by add a MouseAdapter on it. However, it only works when users move the mouse pointer or do some other operations. The code is here: import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JFrame; import javax.swing.JPanel; public class LocationTest { public static void main(String[] args) { LocationTest locationTest = new LocationTest(); locationTest

stop applet flickering with double buffering Java Applet

落花浮王杯 提交于 2019-12-12 01:39:02
问题 sorry to keep asking questions about my program but i think i'm nearly there and i'm teaching myself java so please bear with me. I'm creating an applet that moves sheep object across the screen in a random direction when a dog object moves close to the sheep. Getting the sheep to move in a random direction took some work and with the help of you guys on here it now works (sort of) but what I'm trying to do now is stop it from flickering when i drag objects across the screen. I've read about

how to make text appear when a button is clicked

喜夏-厌秋 提交于 2019-12-12 01:37:41
问题 In my APCS class right now, we are learning how to program GUIs. We have learned about making a button and changing the background color to green, red, blue etc. However, my teacher will not be here for the rest of this week and I was just curious about how I can make text appear inside of the frame with the click of a button, and make the text disappear when I click the button again. If it helps, below is the code. I want to change the background color to green as well as displaying "green"

How to settle an an image in Applet for tetris game

牧云@^-^@ 提交于 2019-12-12 01:34:20
问题 I developing tetris game using applets. I have generated random shapes and making it move. But i don't know how to make it settle at the bottom. My shapes are vanishing once it reaches the end of the screen. Please help me on this regard. Here goes my code. import java.applet.Applet; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; import javax.swing.JLabel; public class TetrisGame { public static void main (String argsp[]) {