awt

How to fix bad Double-Buffering [closed]

孤人 提交于 2019-12-11 19:18:40
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I tried following a double buffering tutorial, and I really don't know what I did wrong. It works before then before I did the tutorial, but there is still and occasional flicker here and there. I have two files

Keeping a MouseListener always running

感情迁移 提交于 2019-12-11 19:17:44
问题 I have this constructor: public Board(final boolean[][] board) { this.board = board; height = board.length; width = board[0].length; setBackground(Color.black); button1 = new JButton("Run"); add(button1); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { isActive = !isActive; button1.setText(isActive ? "Pause" : "Run"); } }); button2 = new JButton("Random"); add(button2); button2.addActionListener(new ActionListener() { public void actionPerformed

Creating new object of a class on button click / actionEvent

亡梦爱人 提交于 2019-12-11 18:19:20
问题 Found solution decided it was easier to simply make a method outside of the actionListener called chairPrice which can be incremented by a method called getItemPrice(). This has been used to calculate the total price of items and works 100% 回答1: You need to use the Object.equals() method. @Override public void actionPerformed(ActionEvent buttonClick) { if(buttonClick.getSource().equals(guiButtons[0])) //if user clicks on 'add chair' { Chair chair = new Chair(); } } Edit in response to the OP

java.lang.IllegalArgumentException: adding container's parent to itself

守給你的承諾、 提交于 2019-12-11 17:56:26
问题 I have following code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GUI extends JFrame { private JLabel text, result; private JTextField volt, amper, ohm, capacity, time, tensionChange, stream; private JButton calculate, next, previous; private JPanel header, panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9, card, pane; private CardLayout cards; private double voltNumber = 0; private double amperNumber = 0; private double ohmNumber = 0;

How to get a Key Event in a Java Swing JFrame instance which has many JTextFields?

喜夏-厌秋 提交于 2019-12-11 17:44:49
问题 I have a JFrame class which implements several JLabels and JTextFields and I would like to perform an action when the focus is on that JFrame and the user press F1. I have created the following class to handle the KeyListener: public class PropertiesKey implements KeyListener, ActionListener { private Properties propertiesWindow; public PropertiesKey(Properties p) { propertiesWindow = p; System.out.println("DEBUG PropertiesKey"); } @Override public void keyPressed(KeyEvent event) { System.out

Java Swing How to scale triangle

丶灬走出姿态 提交于 2019-12-11 16:59:44
问题 I would like to draw some random triangles and scale them, when I'm changing the size of my window. I have a separate class MyTriangle that extends MyShape . I also have two variables: scaleX and scaleY . Whenever I try to multiply triangle x and y values and change the window size, triangles go crazy and suddenly disappear. When I try to write graphics.fillPolygon(new int[]{(int)(x1*scX),(int)(x2*scX)(int)(x3*scX)}, new int[]{(int)(y1*scY),(int)(y2*scY),(int)(y3*scY), 3); Nothing happens in

My simple key listener isn't working. It doesn't seem to toggle the pressed boolean. (Java)

风格不统一 提交于 2019-12-11 16:49:06
问题 I'm using this for a simple 2.5D game but my keys don't seem to toggle. It isn't a problem while calling it in the main class as placing println statements in the if statements didn't run. Thanks ahead of time. import java.awt.event.KeyEvent; import java.awt.event.KeyListener; public class InputHandler implements KeyListener { public InputHandler(Game game) { game.addKeyListener(this); } public class Key { private boolean pressed = false; private int numTimesPressed = 0; public boolean

How can i add 'java.awt.geom' class in android?

浪尽此生 提交于 2019-12-11 16:07:11
问题 I am making a game in LibGDX. When i run in libgdx-desktop, than it works fine. But when i run it in libgex-android than i get this error: ERROR: Could not find class 'java.awt.geom.Line2D$Float[]', referenced from method com.ia.Entity.Player.hit So libgdx-android can't seem to find line2d class. Any idea how can i fix this? Is there way i can just add a jar file or some thing in my libgdx-android project? I really want to use 'java.awt.geom.line2d.flot[]' in android, but if answer is no,

About Metro GUI in desktop application

余生长醉 提交于 2019-12-11 15:06:52
问题 I am making a software that will support multiple features simultaneously. I know the logic, and I have developed the features to support. I want my project to have a look similar to Metro GUI of Windows 8. It need not to be specifically Metro, but similar. I know about all the layouts in standard Swing library. Currently I am using GroupLayout though. How should I proceed, any ideas? Because the UI seems dull and I don't want to use 3rd party APIs either. Any suggestions? 回答1: I personally

Setting LANDSCAPE orientation when printing

一个人想着一个人 提交于 2019-12-11 14:43:42
问题 I need to print an image. When I set orientation like printRequestAttributeSet.add(OrientationRequested.LANDSCAPE); all works fine. But when I set orientation inside print() method of Printable : public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex >= images.size()) return Printable.NO_SUCH_PAGE; image = images.get(pageIndex); // if image width>height --> Landscape, else --> Protrait if (image.getWidth(null) > image.getHeight(null))