awt

How to monitor Event Dispatch Thread queue?

百般思念 提交于 2019-12-02 08:01:16
I have a heavy java project which does not work responsive to the users. I have found out that long time needed events in event dispatch thread can cause my project to work slowly. So, I have two question in this manner: How can I monitor the event dispatch thread and see which events are in the queue and eventually, which ones spend more time in event dispatch thread? ( As you know invokeLater function insert the event to the end of the event dispatch queue. I want to monitor whole event dispatch queue) How can I insert an event to the first of the event dispatch thread? (in this case, the

Overriding the paint() method

断了今生、忘了曾经 提交于 2019-12-02 07:58:40
I've got a beginner question here that I was hoping someone with some Java experience could help me with. Currently taking an intro to OOP course focused on Java. My instructor is currently covering awt and swing, specifically the need to override the paint method so that graphics are redrawn when a window is resized, etc. I like to do as much outside reading as possible, and my concern is that the examples that my professor gives involve things that I've read are not best practices. To get to the point... I understand that it's necessary to override the paint method, but I don't know the best

What are the UIManager keys for JFileChooser and FileDialog?

北城余情 提交于 2019-12-02 07:48:10
I want to use the UIManager.get method in order to get and save the system look and feel for JFileChooser and FileDialog and then I want to change the look and feel. The problem is that I don't know what are the keys for Swing components that UIManager.get method uses. Is there any reference or any convention for that? Thanks UIManager Defaults 来源: https://stackoverflow.com/questions/3974743/what-are-the-uimanager-keys-for-jfilechooser-and-filedialog

Leaving a trace while painting on a transparent JPanel

旧时模样 提交于 2019-12-02 07:41:27
I am relatively new graphics programmer in Java and here is a simple program I was trying. Here is the full code: broken into 3 classes. Class 1: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyPanelB extends JPanel { int x=0; int y=0; public void paintComponent(Graphics g) { x=x+1; y=y+1; setOpaque(false); //setBackground(Color.cyan); g.setColor(Color.red); g.fillRect(x,y,x+1,y+1); } } Class 2: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyFrameB implements ActionListener { MyPanelB p1; public void go() { JFrame f1= new

Repaint is not functioning properly as required

霸气de小男生 提交于 2019-12-02 07:37:35
问题 I have built a tetris game. Now in that I have used a JPanel for displaying content and the blocks (using the paintComponents() method). The problem is whenever I try to call the tetris program from another JFrame it does not paint at all. The code for my tetris main menu is: import javax.swing.*; import sun.audio.AudioPlayer; import sun.audio.AudioStream; import java.awt.*; import java.awt.event.*; import java.io.FileInputStream; import java.io.InputStream; @SuppressWarnings("serial") public

Get Click Count Mouse Listener on Touch Screen

自古美人都是妖i 提交于 2019-12-02 07:31:10
Im running a simple JFrame with a JList. I encountered an issue just like this guy> Java getClickCount on touchscreen I know it has been posted already but there were no answers. jList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.out.println("MouseClick: "+e.getClickCount()); if (e.getClickCount() == 2) { Code below is working.. public class MainTest extends JPanel { public MainTest() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { System.out.println(me.getClickCount()); } }); } public static void main(String[] args) {

Importing Font to GUI

余生颓废 提交于 2019-12-02 07:22:35
I am trying to change the font for my GUI besides the basic 5 that swing seems to come with. How to import fonts and actually use them in my code? There are usually more than 5 available by default, but they change from system to system. This answer examines both the existing fonts, as well as how to load & register new fonts. It uses the 'Airacobra Condensed' font available from Download Free Fonts (obtained by hot-link URL). A font that is in the Jar of your app. is also accessible by URL. import java.awt.*; import javax.swing.*; import java.net.URL; class LoadFont { public static void main

Canvas fillRect() not filling defined canvas

你说的曾经没有我的故事 提交于 2019-12-02 07:13:06
I am extending a Canvas and adding it to a JFrame . I understand that AWT and Swing should not be mixed and that drawing on JPanel is preferred but i'm trying to follow a game engine tutorial and i'd like to stick to it since I got it working so far. The Canvas has minimumSize , maximumSize , and prefferedSize set to the dimensions of 550, 400 . When I do a draw call graphics.draw(0,0,550,400) it doesn't fill the entire screen as it should. I changed the draw call to graphics.draw(0,0,560,410) essentially adding 10px to it and it filled the entire screen. Whats wrong? BTW: graphics.draw(10,10

java.security.AccessControlException when using java.awt.Robot class for screen capture in applet

感情迁移 提交于 2019-12-02 06:42:39
问题 I require to capture a web page screen to store it on client's machine whenever client clicks print screen button. For this I googled and got that by embedding an applet with signature(trusted applet) in my jsp page i can do this. So I am trying with a simple applet for an standalone java class. On success I can try it for jsp after signing the applet. What I tried is: import java.applet.Applet; import java.awt.Graphics; import java.util.Date; import javax.imageio.ImageIO; import java.awt

How to stop the auto-repaint() when I resize the Jframe

a 夏天 提交于 2019-12-02 06:35:47
问题 I am still learning Java, if someone can help me I will be very happy! Sorry for bad english, I am spanish! I am making a tile game, the game uses the classic "game loop" that cap the engine at 60fps The loop sleep and then call repaint(); This works fine! But.. The problem is that repaint event is called when the JFrame is resized or maximized! For example when the JFrame is maximized/resized the game render at 10000fps but when they dont, the game render at the speed I set, so there is a