awt

Floating button is AWT?

早过忘川 提交于 2019-12-11 05:04:22
问题 So, I've always avoided using GUIs in java because, personally, I can't stand GUIs. But, I've started a project which requires me to use GUIs, and, unsurprisingly, I'm having problems.. I have this bit of code.. public class DefaultWindow extends Window { private DefaultWindow(Frame owner) { super(owner); contained = owner; } public DefaultWindow() { this(new Frame("")); contained.setBackground(Color.black); contained.setLocation(0, 0); contained.setSize(1280,720); Button comp = new Button(

Area generation not liking straight lines

Deadly 提交于 2019-12-11 04:59:35
问题 I'm using the area generation and drawing code from Smoothing a jagged path to create collision areas for tile sprites in a JRPG game I'm making in java - Its not a major full blown game, more just a proof-of-concept for me to learn from. The area generation works fine except for straight lines: http://puu.sh/7wJA2.png http://puu.sh/7wJGF.png These images are of the collision outline opened in photoshop (in the background) vs the area that the java code is generating based on the red color

how to add buttons and panels in frame in java awt

亡梦爱人 提交于 2019-12-11 04:47:23
问题 How to make java awt program in which first line contains text-field,next 5 lines contain 5 buttons each and next 4 lines contain 4 buttons each. And how to set the size of those buttons and space between them ? I have tried this using 3 panels but not working. (sample program made by me but is not showing anything) `import java.awt.*; class cal extends Frame { cal(){ Panel p1=new Panel(); Panel p2=new Panel(); Panel p3=new Panel(); p1.setLayout(new GridLayout(2,3)); p2.setLayout(new

JAVA: Substitute one color with another using ColorModel

℡╲_俬逩灬. 提交于 2019-12-11 04:34:17
问题 I need to substitute one color with white on an image. I've read about ColorModel and RGBImageFilter.substituteColorModel, but I don't understand very well. The color I want to substitute is: R: 113 G: 75 B: 96 And of course, white is 255,255,255. If you can give a direct solution will be great, but if not, a bit of explanation on how to do it also will be great. I don't want just the solution, I want to understand the hows and whys. Thank u so much. 回答1: At my company we have to do this sort

How to get time between mouse moves?

橙三吉。 提交于 2019-12-11 04:08:26
问题 I'm trying to get the millisecond time between times when the mouse moves. I'm using a library for the mouse move event so that it works globally. The problem is that with the code below the time is always zero. @Override public void mouseMoved(GlobalMouseEvent event) { //times the mouse has moved moveCount++; //if it's the first time moving mouse then it's the start time if (moveCount % 2 != 0) { startTime = System.currentTimeMillis(); } //if it's the second time moving the mouse then it's

Using a canvas object in a thread to do simple animations - Java

别来无恙 提交于 2019-12-11 04:06:59
问题 I have an applet that, as written now, should be drawing and bouncing a ball around the top ( drawingpanel in the code) after the "Run" button is pressed. Looking at other examples online and using code from a different program that did not use Canvas I am not able to figure out why my Ball object is not showing up. I have tested the flow of the program, and all the methods are being called as they should be, so it isn't the case where the code doesn't make it to the paint method. Any good

Force full redraw of a Jpanel Java2D

不打扰是莪最后的温柔 提交于 2019-12-11 03:09:16
问题 My question is that i need to make a GUI that keeps updating becuse i get values that can change from a DB and i got some problems in the graphical area. well im using Drawline and Drawstring from Graphics2D that print values that are found on the database, this strings and lines move and change value, so i need to call repaint(); with a timer to make them apper in the jpanel, the problem is that repaint(); is not removing the old painting in the background before painting, but when i resize

Java select items

只谈情不闲聊 提交于 2019-12-11 02:40:54
问题 I just began my adventure with java. I have written an application with a panel and three buttons. But I have a problem. I want to add selection this buttons using the mouse. I mean like we have in Windows on the Desktop. I press the left mouse button and with the movement of the mouse the area selection is growing. And I have a question. Is there a specific interface in this or do I have it manualy, call the appropriate methods for event listeners and there draw transparent rectangle? Here

What is sun.awt.windows.WToolkit?

时光毁灭记忆、已成空白 提交于 2019-12-11 02:34:18
问题 I have the following piece of code import java.awt.*; import java.awt.event.*; import java.lang.reflect.*; import javax.swing.*; class QueueTest { static int i=0; public static void main(String[] args) throws InterruptedException, InvocationTargetException { EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); eventQueue.push(new MyEventQueue()); Frame f=new Frame(); f.setSize(400,400); //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocation(150,150); f

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException if-statement

大兔子大兔子 提交于 2019-12-11 02:01:40
问题 I'm developing a tic tac toe game and have one problem - Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException, it occurs when i try to press the button. The buttonText is changed to X, but after that i get the problem. I believe there is something wrong with if statements: The source code of Main.java: package mytictactoegame; public class Main { public static boolean playerTurn = true; public static boolean playerWon = false; public static boolean compWon = false; public