awt

why is paintComponent() never called by repaint()?

北战南征 提交于 2020-01-25 05:57:44
问题 I've been working on an program that draws custom JComponents onto a JLayeredPane however all calls to repaint() on the components seem to do nothing yet the paintComponent method is invoked automatically when the window is re-sized. I have been following some of the advice given here: Why is paint()/paintComponent() never called? But none of the solutions seem to fix my problem, update swing components on the EDT, setting component size manually before calling repaint(), calling super

How can I limit the check box selected?

筅森魡賤 提交于 2020-01-25 01:03:10
问题 We were told to have 10 checkboxes and the user is only allowed to check 1-3 check boxes. After the user clicks a button indicating that he/she has completed the requirements and after the computer randomly selects a checkbox. The remaining checkbox wil be delared as a winner. This is a gaming program by the way. I'm using Swing and AWT. 回答1: You can limit a checkbox being selectable or not by disabling the component: JCheckBox checkBox = new JCheckBox("Try to click on me"); checkBox

Java GUI Rotation and Translation of Rectangle

孤街醉人 提交于 2020-01-23 08:06:30
问题 I am trying to draw a rectangle in JPanel that would translate and then rotate itself to mimic the movement of a car. I have been able to make the rectangle translate and rotate, however it rotates around the origin of (0,0). I'm very pleased that I was able to have the rectangle move and rotate as I am very new to Java GUI, but I can not seem to get how to have the rectangle rotate around itself, because I experimented more with it, and when I initialized the rectangle and rotate it 45

How to rotate text with Graphics2D in Java?

寵の児 提交于 2020-01-23 04:37:33
问题 I want to rotate text on a JPanel using Graphics2D.. My code is this: double paso=d.width/numeroBarras; double alto=datos[i].valor; Font fBarras=new Font("Serif", Font.PLAIN, 15); g2.setFont(fBarras); Rectangle2D barra=new Rectangle2D.Double(x,d.height-alto,paso,alto); //g2.fill(barra); x+=paso; g2.draw(barra); g2.rotate(-Math.PI/2); g2.setColor(Color.BLACK); g2.drawString(datos[i].titulo,(float)alto,(float)paso) This method must draw a rectangle and a text over the rectangle, but when i run

How to fix java.awt.HeadlessException in Jenkins on Linux

僤鯓⒐⒋嵵緔 提交于 2020-01-22 02:01:33
问题 I use some AWT code in my Java app which ran fine until I unit tested it on Linux Mint Debian Edition via Jenkins and Gradle: I now get that nasty java.awt.HeadlessException which is explained here. The unsuccessful unit test causes my build to fail; how do I fix that? 回答1: These are the steps that rid me of the HeadlessException: Add the Xvnc plugin to Jenkins Install VNC: sudo apt-get update && sudo apt-get install vnc4server Make sure Jenkins has a shell: sudo usermod -s /bin/bash jenkins

I am trying to move a ball in applet using thread but its not moving

半世苍凉 提交于 2020-01-21 18:39:58
问题 I am trying to move a ball in applet using thread but its not moving. Can anyone help me out as m new to applet and proceeding for game development..for reference here is my code public class ballGame extends JApplet implements Runnable { int x_pos=50; int y_pos=100; int rad=10; Thread t; public void start() { super.start(); t=new Thread("t"); t.start(); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); setBackground(Color.BLACK); g.drawOval(x_pos,y_pos,2*rad,2*rad);

I am trying to move a ball in applet using thread but its not moving

霸气de小男生 提交于 2020-01-21 18:39:04
问题 I am trying to move a ball in applet using thread but its not moving. Can anyone help me out as m new to applet and proceeding for game development..for reference here is my code public class ballGame extends JApplet implements Runnable { int x_pos=50; int y_pos=100; int rad=10; Thread t; public void start() { super.start(); t=new Thread("t"); t.start(); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); setBackground(Color.BLACK); g.drawOval(x_pos,y_pos,2*rad,2*rad);

Java: use Robot while running fullscreen app

你说的曾经没有我的故事 提交于 2020-01-21 11:51:03
问题 I have a problem with Robot class in Java: it sometimes doesn't work when i run a fullscreen game. Here's my code: Toolkit tlkt = Toolkit.getDefaultToolkit(); Robot bot = new Robot(); while(true) { Thread.sleep(3000); tlkt.beep(); //make sure that program still runs bot.mousePress(MouseEvent.BUTTON1_DOWN_MASK); bot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK); } I want to left-click every 3 seconds and beep for sure. It work fine but when I run some full-screen application, then it just beeps

Java: use Robot while running fullscreen app

南笙酒味 提交于 2020-01-21 11:50:26
问题 I have a problem with Robot class in Java: it sometimes doesn't work when i run a fullscreen game. Here's my code: Toolkit tlkt = Toolkit.getDefaultToolkit(); Robot bot = new Robot(); while(true) { Thread.sleep(3000); tlkt.beep(); //make sure that program still runs bot.mousePress(MouseEvent.BUTTON1_DOWN_MASK); bot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK); } I want to left-click every 3 seconds and beep for sure. It work fine but when I run some full-screen application, then it just beeps

JAVA can't paint onto JFrame from within another class

痴心易碎 提交于 2020-01-21 10:24:35
问题 I am aware this is my error. My question is why isn't this working what am i missing i can call this is i put it a method instead of a class so i am assuming theirs something wrong with the third class? Class 1: package assignment.pkg1.java; import java.awt.Color; import javax.swing.JFrame; public class JVMVeiwer { /** * @param args the command line arguments */ public static void main(String[] args) { final int FRAME_WIDTH = 1000; // Frame Width final int FRAME_HEIGHT = 800; // Frame Height