jframe

how do i clear my frame screen in java?

僤鯓⒐⒋嵵緔 提交于 2019-12-22 00:36:18
问题 I am making a brick game. I want the screen to get clear after every 0.1 second so that i can redraw every thing on the frame screen. Is there any way to directly clear the frame screen without any event occurence?? 回答1: You should override public void paint(Graphics g) and do all your drawing in there. Then you start a timer, which calls repaint(); Here is a basic example: public class MainFrame extends JFrame { int x = -1; int inc; public MainFrame() { Timer timer = new Timer(10, new

How to add imagepanel in jpanel inside Jframe?

二次信任 提交于 2019-12-22 00:00:06
问题 I'm trying to add an imagepanel which extends JPanel to another JPanel. Which is not working well for me. The paint function of image panel don't get invoked inside Jpanel but works fine in JFrame. Any ideas or help will be appreciated. import javax.swing.*; import java.awt.*; import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; class ImagePanel extends JPanel { int g_h=10,g_w=10; int width=50,height=50; int cornerradius; Image castle; Dimension size; protected int x1

Why Timer does not work if we do not generate a window?

血红的双手。 提交于 2019-12-21 20:28:49
问题 Here is the code: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.Timer; public class TimerSample { public static void main(String args[]) { new JFrame().setVisible(true); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Hello World Timer"); } }; Timer timer = new Timer(500, actionListener); timer.start(); } } It generates a window and then

MouseEvent lost in JScrollPane

旧时模样 提交于 2019-12-21 20:09:59
问题 This is the code I am using to show the issue which I am facing in another project. I am not getting any line like this if I use JScrollPane as a wrapper for panel2. Why? I want to click on JscrollPane and got event printed as following. java.awt.event.MouseEvent[MOUSE_CLICKED,(800,469),absolute(808,499),button=1,modifiers=Button1,clickCount=1] on javax.swing.JPanel[,0,0,934x612,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.LineBorder@cc0e01,flags=9

Swing: Change cursor to wait cursor

妖精的绣舞 提交于 2019-12-21 16:57:46
问题 See also Java Swing GUI hour glass. However the provided answer does not seem to work. I have following code: private void loadFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) { int returnVal = fileChoser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // do stuff } finally { this.setCursor(Cursor.getDefaultCursor()); } } } This is called when user selects the according entry in the menu bar

Transparent JFrame background

不想你离开。 提交于 2019-12-21 11:22:11
问题 Is it possible to make a JFrame that has a transparent background and draw an image on it, so only the image will be visible with no border or background? 回答1: See Translucent and Shaped Swing Windows by Kirill Grouchnikov. 回答2: Yes, it's possible in many ways. This is one of them: setUndecorated(true); setBackground(new Color(1.0f,1.0f,1.0f,0.5f)); 4th float (which I set to 0.5f) in Color's constructor is alpha channel. It can be 0.0f - 1.0f depend on transparency you want. 回答3: It is

Stop Eclipse/Java running multiple instances

≡放荡痞女 提交于 2019-12-21 06:50:07
问题 I'm not a java expert or a eclipse expert. Currently I'm working on a project and i need to debug/test often. I use the eclipse run Button for it. But when I don't close the Program eclipse/java opens it again(second window). It's an gui app with swing jframe. Is there a function in eclipse or java to terminate the previous build and opens the new one when you run it? 回答1: Try the following ways: If you are in debug perspective, you can Right click running instance and click "Terminate and

Create a transparent JFrame in java swing

与世无争的帅哥 提交于 2019-12-21 05:22:27
问题 Hello everyone im made a swing application in java, but problem is that how i can achive the transparent frame in java. I want to make a user interface design as in attach image, but probem is that frames is not transparent, so it showing the default color if there is no components on that layer. Like on the right side i want to show this frame as a transparent on the top free and bottom free portion, I use AWTUtilities, but it not works for me. how can i do it, plz reply, also give me a hint

JLabel and JLayeredPane - How to display an image over another image?

拜拜、爱过 提交于 2019-12-21 05:16:10
问题 I try to create a little game in java but I'm in trouble. When I draw a map, I'm not able to display the characters without overwrite the titlesets of the squares. My goal is to be able to display many pictures on the same square (like the titleset of the grass, the character and a tree), so I have to deal with the transparency of my pictures (this is not the problem) and the layer (it is the problem). So how can I display an image on another image? How can I explain to java that I need to

JAVA: Ways to fill a Frame. add(), setContentPane(), getContentPane()

守給你的承諾、 提交于 2019-12-21 03:40:31
问题 I found three ways to fill my JFrame frame = new JFrame("...") createContentPanel returns a JPanel and createToolBar returns a ToolBar. frame.add(this.createToolBar(), BorderLayout.PAGE_START); //this works and puts the ToolBar above and the ContentPanel under it<br> frame.add(this.createContentPanel(), BorderLayout.CENTER); frame.setContentPane(this.createContentPanel()); //this lets the JToolBar hover over the ContentPanel frame.getContentPane().add(this.createToolBar()); frame