jframe

Is there anyway to add text inside picture in JFrame?

冷暖自知 提交于 2019-12-01 13:15:03
问题 EDIT:Damn, my english is a bit off. I meant to ask how to add text "inside" picture not over(above) it , with the text be at the center of picture. thank you for previous helps anyway :). 回答1: Sure. Paint the text direct to the picture. Display the picture in a label. E.G. How to edit a text that is converted into image? How to resize text in java Of course, if you want it 'simpler' there are other options. One is OverlayLayout as described by @Reimeus. Here is another. It utilizes the fact

How to animate Rectangle in JPanel?

主宰稳场 提交于 2019-12-01 13:07:41
I want to learn some tricks about JAVA for my project. I want to animate my Rectangle leftoright and righttoleft but I can't apply the same functions for ball animation. In addition,how can I start my ball in different x-direction with a border of y-coordinate ? Thanks a lot for your advices and helping. My codes: import javax.swing.Timer; import java.util.ArrayList; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MultipleBall extends JApplet { public MultipleBall() { add(new BallControl()); } class BallControl extends JPanel { private BallPanel ballPanel = new

Java Making objects move while buttons held

纵然是瞬间 提交于 2019-12-01 12:58:32
问题 How do I make a JPanel move while a button is held down and stop when the button is released. I have tried using thread.start() with a Runnable and ways like that. I always run in to errors. Can anyone help me though? 回答1: There are a number of important considerations that you need to take into consideration. Buttons aren't designed to work this way. They are designed to trigger and action event when they are clicked (pressed and released), so you can't use the normal action API. Lucky for

Weird white space in a java JFrame

不羁岁月 提交于 2019-12-01 12:54:55
问题 Here is my problem. When i use the following code: package xyz.lexium.giapb.ui; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ConsoleWindow extends WindowAdapter implements WindowListener, ActionListener, Runnable { private JFrame frame; private JTextArea textArea; private Thread reader; private Thread reader2; private boolean quit; private final PipedInputStream pin = new PipedInputStream(); private final PipedInputStream pin2 = new

Java JApplet to JFrame

一个人想着一个人 提交于 2019-12-01 12:35:19
I want to convert a JApplet to a JFrame. I have found this code on the internet that is a word search game. I want to use this code in a demonstration for a class. but I don't want it in an applet. The code that I was going to paste in here was to large by about 7,000 characters. I tried taking the JApplet and extending a JFrame and then putting all of the code for the initialization into a constructor (Zero Argument constructor). This cause about ten errors that I couldn't get fixed. I want to make a word search game and I had found a great example but I cannot get it to run in my Eclipse.

Lag spike when moving player

风格不统一 提交于 2019-12-01 12:30:23
The player is a panel, and it is getting removed, its position changed, and then re-added to another panel (which is what contains this method) which is drawn to the main frame. There are also a lot of other small panels containing a grass sprite being drawn to the primary panel as terrain tiles. I think the problem is that when I call revalidate() , it revalidates all those little panels as well. How can I solve this? EDIT: I should mention that I am using RelativeLayout to position the players on the primary panel. private class MainKeyAdapter extends KeyAdapter { @Override public void

While loop with delay makes JFrame unresponsive

旧巷老猫 提交于 2019-12-01 12:25:11
问题 So, my JFrame becomes unresponsive when I run this code. I managed to trace it back to the while loop under gameLoop(). Regardless of using delay(1000/FRAMERATE) which calls Thread.sleep() within it, it will not allow the Key or Mouse Listeners to do their job. Full code below, problem exists in gameLoop() package me.LemmingsGame; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class Game extends JFrame implements KeyListener, MouseListener{ private

How do I start optimising my Java code? - CPU is at 100%

六眼飞鱼酱① 提交于 2019-12-01 11:41:44
i have written an application, but for some reason it keeps peaking at 100%. I ran a profile r on a few of the classes and a report show that isReset() and isRunning() seems to be called alot of times. Do you see anything wrong please inform me. thanks Class 1 is the only class that uses the isReset() code so i hope this helps u guys in detecting the error Class 1 package SKA; /* * ver 0.32 June 2009 * * Bug Fix Release: * * Fixed Array resize * Fixed Red Black Tree delete method * Fixed Red Black Tree save/read option * Update help file * */ /* * Additions: * ver 0.30 May 2009 * * Added Red

Custom design for Close/Minimize buttons on JFrame

微笑、不失礼 提交于 2019-12-01 11:21:30
I would like to apply my own close and minimize buttons. Is there any way to change the JFrame design? The trick lies in the PLAF and setDefaultLookAndFeelDecorated(true) ( Specifying Window Decorations ). E.G. import java.awt.BorderLayout; import javax.swing.*; public class FrameCloseButtonsByLookAndFeel { FrameCloseButtonsByLookAndFeel() { String[] names = { UIManager.getSystemLookAndFeelClassName(), UIManager.getCrossPlatformLookAndFeelClassName() }; for (String name : names) { try { UIManager.setLookAndFeel(name); } catch (Exception e) { e.printStackTrace(); } // very important to get the

replacing the dot character in the password field, Jframe, Java

◇◆丶佛笑我妖孽 提交于 2019-12-01 11:06:14
问题 I want to ask how can i change the character in the password field that was the point I want to replace with a star ??? i'm using Jframe, Java 回答1: PasswordTextField.setEchoChar('*'); 来源: https://stackoverflow.com/questions/13390247/replacing-the-dot-character-in-the-password-field-jframe-java