awt

How to edit a text that is converted into image? or any other approach to realize/edit text

大兔子大兔子 提交于 2019-11-28 10:34:38
问题 For my project I want to resize text just like in Adobe Photoshop. But when I tried resizing(by mouse drag) the textpane, only the textpane was getting resized and not the text inside it. Then I tried converting my text to image and tried resizing it again (As mentioned in the post How to resize text in java) and it worked fine.. Now I have another problem of editing my text. i.e. once my text is converted to image then how do i edit it (eg: changing the text color, etc). Any idea on this?

Is it possible to write your own objects that give out ActionEvents?

只谈情不闲聊 提交于 2019-11-28 10:31:41
问题 I've looked at the java tutorials online and they all seem concerned with catching ActionEvents given out by other components that are already written. Is it possible to write your own objects that have there own set of criteria that trigger actionEvents that can then be caught by other classes that have registered as listeners? So for example: If I wanted an object that was counting sheep to send out an actionEvent when 100 sheep had been counted to all the sleeper objects that had

Why does InvokeLater cause my JFrame not to display correctly?

六月ゝ 毕业季﹏ 提交于 2019-11-28 10:25:29
Ok I've read an searched all over the web, and I've not found the solution to my problem yet, perhaps I'm missing something simple, hence here I am... I've got a rather large project, that handles work orders for a repair business. It's all database connected, many many pages of code, and classes. But i just added a short bit of code to the front end that essentially checks for new messages in our notes area. Anyway, I display a simple JFrame with two JLabel s while a separate thread queries the database. This all happens at the start of the program. The problem is my little "please wait"

Triangle Draw Method

ぃ、小莉子 提交于 2019-11-28 09:45:56
I have trouble drawing a triangle with the draw(Graphics g) method in Java. I can draw a rectangle like so: public void draw(Graphics g) { g.setColor(colorFill); g.fillRect(p.x, p.y, width, height); g.setColor(colorBorder); g.drawRect(p.x, p.y, width, height); drawHandles(g); Where p represents "the top left corner of the shapes". How would I draw the triangle in the same manner? Could someone give me an example for a standard triangle? davidbuzatto There is not a drawTriangle method neither in Graphics nor Graphics2D. You need to do it by yourself. You can draw three lines using the drawLine

Frame and Canvas grow larger than specified

血红的双手。 提交于 2019-11-28 09:42:19
问题 I have no idea why I am getting an extra-large window, this is making me run hoops to fit my sprites in the game-window. The constructor should make it so all the subcomponents fit into eachother, but it seems like there is some extra padding in the canvas or frame. I am having a tough time figuring out what the culprit is. The size of my frame should NOT be larger than 800x600 (OS decoration not included, talking about the containers). Panel: java.awt.Rectangle[x=0,y=0,width=810,height=610]

java draw line as the mouse is moved

◇◆丶佛笑我妖孽 提交于 2019-11-28 09:33:56
I would like to add a feature to my application which allows the user to draw a straight line by clicking the mouse at the start location and releasing it at the end location. The line should move as the mouse moves until it is finally released; similar to the way that a line can be drawn using the Microsoft Paint application. How can implement this so that the line is repainted as it moves without repainting other things that may already be drawn in that rectangular area? Try this...Draw a red line on the screen as the mouse is moved (dragged). public static void main(String args[]) throws

How to move a mouse smoothly throughout the screen by using java?

久未见 提交于 2019-11-28 09:31:40
There is a mouseMove()method that makes the pointer jump to that location. I want to be able to make the mouse move smoothly throughout the screen. I need to write a method named mouseGLide() which takes a start x, start y, end x, end y, the total time the gliding should take, and the number of steps to make during the glide. It should animate the mouse pointer by moving from (start x, start y) to (end x, start y) in n steps. The total glide should take t milliseconds. I don't know how to get started can anyone help me get started on this? Can anyone just tell me what steps I need to do in

Flipping shape (not image)

这一生的挚爱 提交于 2019-11-28 09:29:38
问题 Solved: Thanks @MadProgrammer I replaced g2.rotate(Math.toRadians(180.0)); by g2.scale(1, -1); thanks^^ I wrote program to show Digital Clock with mirror (Vertical Flip) This is my code import java.awt.*; import java.awt.font.GlyphVector; import javax.swing.*; import java.util.*; public class DigitalClock extends JFrame implements Runnable { /** * @author HASSAN */ Thread runner; // declare global objects Font clockFont; Shape mirror; public DigitalClock() { super("Digital Clock - Hassan

About the EDT (Java)

浪尽此生 提交于 2019-11-28 09:22:51
问题 I have read a number of articles on the internet about when something should run in the EDT, and when it shouldn't. But I'm still not sure I understand, so I'd like to ask a few question about this: What pieces of code are going to run by default inside the EDT? What pieces of code are going to be run be default outside the EDT? When should I use InvokeLater() so something that by default would run outside the EDT, will run inside it? When should I prevent a piece of code from running (by

Debug exceptions in AWT queue thread

时光总嘲笑我的痴心妄想 提交于 2019-11-28 09:10:25
问题 I am developing a Swing application with a component performing custom painting. When I make some mistake in the painting code and an exception is thrown, the situation is hard to debug. Instead of being caught by the debugger, a popup shows with the exception information. Moreover, the thread seems to be restarted, and as the exception is a result of coding error, it is shown again and again. When I am lucky enough to switch into the debugger (which is difficult, because more and more popups