awt

SWT - get actual screen position of an image

别说谁变了你拦得住时间么 提交于 2019-12-24 15:55:54
问题 I have drawn an image on a Composite using the following code imageCanvas = new Composite(shell, SWT.BORDER); //adding paintListener to the canvas imageCanvas.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { if (sourceImage != null) { // draw the image e.gc.drawImage(sourceImage, 120, 150); //check the bounds of the image using the getBounds function Rectangle newrec = sourceImage.getBounds(); System.out.println("X: " +newrec.x + " Y: "+newrec.y ); //

How to properly wait until ActionListener is executed?

寵の児 提交于 2019-12-24 15:07:21
问题 I have a simple, variably sized tic-tac-toe App that works differently on different machines. On my laptop it works like I want it to and on my desktop, it gets stuck in the ButtonListener class that implements ActionListener . I'm pretty sure this is because of the way I am waiting for a action to be performed, using a while loop. Here is the offending code snippet. public void playOneTurn(int player) { waiting = true; while (waiting) { // Do nothing, touchEvent will change waiting. } } I

Why doesn't the keylistener work?

让人想犯罪 __ 提交于 2019-12-24 14:47:59
问题 I'm trying to run a code I wrote for a moving ball (sorry if the code is messy... i'm not very experienced... ) it doesn't show any error messages but when I click at the appletviewer and press the keys, the ball doesn't change it's direction. Why does that happen? p.s. I'm using "eclipse" for writing my codes is it a good compiler? maybe the problem is there? import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.applet.Applet; import java.awt.Color; import java.awt

Disable close button in Processing

懵懂的女人 提交于 2019-12-24 13:16:34
问题 Is there a way to disable the window's close button in Processing, during a certain event? Here is a snippet of the code: frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { if (youWin == 0) // condition that is supposed to keep the application opened { JOptionPane.showMessageDialog(frame,"You can't exit until you finish this game. OK?"); // keep applet opened } } } ); EDIT: I want to do it without using JFrames. 回答1: Edit: This answer is for Processing 2

How to see BufferedImage in JPanel?

纵饮孤独 提交于 2019-12-24 12:34:21
问题 I'm building a PongClone but I encounter a bug. **I think the bug is cause by JPanel. I tried the Image instead of BufferedImage. I tried the drawImage outside the paintComponent method. I create to another panel and then add that panel inside a mainpanel. Menu Class package me.pong; import javax.swing.*; public class TestMenu { JFrame frame; public void createFrame () { TestMain main = new TestMain (); frame = new JFrame("TEST"); frame.setSize (800, 450); frame.setDefaultCloseOperation

Canvas not drawing to JFrame

帅比萌擦擦* 提交于 2019-12-24 12:09:27
问题 I've been looking around for an answer to this, re-written my code multiple times, still nothing. Essentially I am trying to draw to a JFrame containing just a simple rectangle, yet each time nothing shows in the Frame - its just blank. package com.Graphics; import java.awt.*; import java.awt.image.*; import javax.swing.*; public class GraphicsMain { public static void main(String[] args) { GraphicsMain myGraphics = new GraphicsMain(); myGraphics.createDisplay(); } void createDisplay(){ int

The Page Turn Effect in Java Swing/AWT

て烟熏妆下的殇ゞ 提交于 2019-12-24 12:00:28
问题 I would like to implement the page turn effect in Swing/AWT. The theory is pretty much explained here. My question is that since the page is to contain text, which is the correct swing/awt component to use? Also, to get a little deeper, how should I approach this problem? I mean I have the theory laid out before me, I know the tool I need to use, but I have never done anything like this with Swing/AWT, do I need to master all the minutiae of Swing/AWT to be able to do this? 回答1: Whatever you

Checking if a rectangle intersects text

别等时光非礼了梦想. 提交于 2019-12-24 10:59:35
问题 I have a class called 'MapObject' which allows you to define what it is, what it does. I have recently added text to this, and it works fine however the collisions is a rectangle, which in some scenarios isn't horrible, however I would prefer to have a collision box matching the text (aka check if a 1x1 rectangle collides with the text but can still be inbetween letters) I have tried the following: GlyphVector vec = ob.font.createGlyphVector(new Canvas().getFontMetrics(ob.font)

How to stop flickering in java.awt.graphics?

旧街凉风 提交于 2019-12-24 08:53:59
问题 So i started to learn Java and tried to create a basic pong game using java.awt.graphics. After finishing it i saw that it was a lot of flickering to the point when the game was unplayable. This is my main class named "pong"(What a creative name). package pong; import java.applet.Applet; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; public class pong extends Applet implements Runnable,KeyListener { public static void main(String[] args){} public final

Drawing a triangle in java

痞子三分冷 提交于 2019-12-24 08:06:19
问题 So a section of my assignment is to make a triangle class to be linked to various buttons...but I'm not sure how to make one in eclipse. The specific instructions say this: Create a triangle class Data fields: Point[] coords; constructors Implement all abstract methods defined in superclass Getters and setters for each data field Override public void paint(Graphics arg0) method I have everything set up in the other classes..except for the triangle class. I'm confused on how to create a