awt

How can I check that JButton is pressed? If the isEnable() is not work?

强颜欢笑 提交于 2019-11-26 11:38:53
问题 How can I check that JButton is pressed? I know that there is a method that its name is \"isEnabled\" So I try to write a code to test. this code have 2 Jbuttons which are \"Add\" Button and \"Checkout\" button. the code will show the \"Add button is pressed\" message when I press \"Checkout\" button after I press \"Add\" button but If the \"Add\" Button is not pressed before the \"Checkout\" Button is pressed, the code will show the \"Add Button is not pressed\" message. Here the code: final

Get mouse detection with a dynamic shape

你说的曾经没有我的故事 提交于 2019-11-26 11:37:04
问题 Basically I\'m constructing a world map. I know how to have a square click area. But I\'d like to make it so I can put the countries together and be able to click on the country. Now it\'s pretty obvious that I can\'t use square click areas for that because I\'d have overlapping click areas. Could I do it by looking at the transparency of each pixel? Even so I don\'t know how to do that? 回答1: Use Shape.contains(Point2D) - something like this: This example uses overlapping ellipses to show how

How can I make this JButton visible? When I have progressive scan background JWindow()?

半城伤御伤魂 提交于 2019-11-26 11:35:49
问题 How can I make the JButton visible? 1) When no progressive background is turned on: JButton is showing 2) When no progressive background is turned on, JButton is pressed still showing no flicker: 3) When progressive background is turned on, JButton is invisible and on pressing in this I see flicker and JButton() appears and again hides auto. << Problem is here, so how can I fix it? import java.awt.Color; import java.awt.AlphaComposite; import java.awt.BorderLayout; import java.awt.Graphics;

How can a Swing WindowListener veto JFrame closing

对着背影说爱祢 提交于 2019-11-26 11:34:52
问题 I have a frame, and want to prompt when the user closes it to save the document. But if they cancel, the frame shouldn\'t close. frame.addWindowListener(new SaveOnCloseWindowListener(fileState)); ... public class SaveOnCloseWindowListener extends WindowAdapter { private final FileState fileState; public SaveOnCloseWindowListener(FileState fileState) { this.fileState = fileState; } public void windowClosing(WindowEvent e) { if (!fileState.onQuit()) cancelClose(); } } FileState looks at whether

Java rotating non-square JPanel component

微笑、不失礼 提交于 2019-11-26 11:33:39
问题 I am attempting to rotate a GridLayout filled with text labels to simulate a portrait orientation view due to an OS restriction. The JPanel they are inside of is not square, so when rotating 90 degrees the labels cut off based on dimensions of the JPanel. Is it possible to resize the layout based on the rotation to still fit within the JPanel? Researching into this showed many options for rotations, but only for square JPanels. To further explain my problem: when I rotate the labels painted

How can I scroll more than one object at the same time?

梦想与她 提交于 2019-11-26 10:48:27
New question was asked after this one, found here . I'm new to Java, but I am working on a recreation of "Flappy Bird" to learn more about java and the way that graphics are displayed. Any solutions or suggestions to any of my questions is greatly appreciated. Thanks! Right now, my program makes a random pipe and scrolls it, but I don't need it to keep scrolling when x1-3 = -83 ( this is when the pipe will be off of the screen completely and is no longer needed ). Questions How can I make my Game.class scroll more than one instance of Pipes.class while adding a preset distance between them? I

how to drag and drop files from a directory in java

笑着哭i 提交于 2019-11-26 10:47:08
问题 I want to implement dragging and dropping of files from a directory such as someones hard drive but can\'t figure out how to do it. I\'ve read the java api but it talks of color pickers and dragging and dropping between lists but how to drag files from a computers file system and drop into my application. I tried writing the transferhandler class and a mouse event for when the drag starts but nothing seems to work. Now I\'m back to just having my JFileChooser set so drag has been enabled but

Java: using an image as a button

蹲街弑〆低调 提交于 2019-11-26 10:40:12
问题 I would like to use an image as a button in Java, and I tried to do this: BufferedImage buttonIcon = ImageIO.read(new File(\"buttonIconPath\")); button = new JButton(new ImageIcon(buttonIcon)); But this still shows the actual button behind the image, I would only like the image to function as the button, how can I do this? 回答1: Remove the border like so: button.setBorder(BorderFactory.createEmptyBorder()); and then also the contents 1 : button.setContentAreaFilled(false); 1 : Taken from the

Porting a Java app that uses AWT and Swing for drawing movies to the server-side

狂风中的少年 提交于 2019-11-26 10:03:35
问题 I am working with some code that writes animated output to the desktop using AWT and Swing features. It draws using 2D graphics and renders text in fonts. This code can use the Java Media Framework to save the animationto movie files. I would like to port this code to a pure server-side environment, for working with a Web UI. The drawing code could either run inside the servlet container, or outside as a command-line program. (Or I could opt not to use a servlet container and instead use the

Why are my items not showing up in JFrame?

删除回忆录丶 提交于 2019-11-26 09:56:03
问题 I\'m fairly new to JFrame and I want to know why my items are not showing up on the window. I know i dont have a ActionHandler but I just want my textfield\'s to show up on my window. Here\'s my code: import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class FirstGUI extends JFrame{ public void GUI(){ setTitle(\"Welcome\"); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);