jframe

Waiting for a JFrame and then retrieving information from it

会有一股神秘感。 提交于 2019-12-12 01:36:50
问题 First of all I'm new to Java and you'll probably be able to guess. Thanks in advance. I'm currently writing a board game using Java for an assignment. There are human and computer player classes, and the GUI only in the human player class. In the human class I use a class called 'UI' extending JFrame where the user selects a piece. At the moment this UI class waits for the enter button to be pressed then sets a 'done' variable to true. In the human player class I create this UI then wait in a

Calling paintComponent() with parameters using repaint()

那年仲夏 提交于 2019-12-12 01:31:54
问题 I am very new to graphics with Java, so just ask if any additional information is needed :) I am trying to paint shapes based on where the mouse clicks on the screen. Because of this, I need to pass the x and y coordinates of where I clicked to the paintComponent() method so that it will know where to paint the shape. public void mouseClicked(MouseEvent e) { System.out.println("Adding Shape"); repaint(); } class CanvasDrawArea extends JPanel{ //this should run when the program first starts

Loading an image into a background in java

北慕城南 提交于 2019-12-12 01:28:44
问题 How do you load an image into a background in Java? I have tried many different methods and none of them work so I am asking if anyone knows how to upload a png image into a jpannel 回答1: Make your own JPanel. Add an object of PicPanel in your GUI's constructor. class PicPanel extends JPanel{ private BufferedImage image; private int w,h; public PicPanel(String fname){ //Pass picture's filename as a parameter. //reads the image try { image = ImageIO.read(getClass().getResource("/"+fname)); w =

Adding a canvas to a panel doesn't show the canvas?

被刻印的时光 ゝ 提交于 2019-12-12 01:12:02
问题 First of all: sorry, if this question was asked before, but I cannot seem to find an answer anywhere, so here we go: I am trying to get a canvas element to show while it being added to a panel with a titled border around the panel. Here is my code. public class TestClass extends JFrame{ private TestClass() { GuiCanvas canvas = new GuiCanvas(); setTitle("TestClass"); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(1300, 800); Border menuBorder = BorderFactory.createTitledBorder( BorderFactory

JFrame minimized to dock name “java”

◇◆丶佛笑我妖孽 提交于 2019-12-12 01:06:01
问题 I am displaying a JFrame on OS X and am getting "java" for the name of the application when it is minimized to the dock. I am passing -Xdock:name="Foo" , and this is changing the name in the dock when the application is not minimized, but once we minimize the name in the dock is wrong. To minimize I am calling setExtendedState(JFrame.ICONIFIED) . 回答1: To get this effect on Mac OS X, you'll need to add the option to your application bundle's Info.plist , as shown in the example cited here.

JFrame is not removed from the taskbar

a 夏天 提交于 2019-12-12 01:05:07
问题 This question is related to my previous question Showing JDialog on taskbar does not look good. I have modified my code so that the dialog is displayed correctly but now the problem is that the button does not disappear from the taskbar when the dialog is closed. So the application runs, a dialog is displayed and a button is created in the taskbar for it. When I choose YES or NO, the dialog is closed but the button remains in the taskbar. For this reason, buttons add up in the taskbar each

Passing data to new GUI

久未见 提交于 2019-12-12 00:54:09
问题 I have a JTable with contents on it which I have read from a CSV file. I am using the following method which when I click on a row it will open up a new JFrame and close the previous one. It will display things such as ID, co-ordinates, status of what is written on that table and can edit them if wanted. E.G. table below: |ID |co-ordinates | status | | 1 | (3,21) | pending | | 2 | (4,21) | full | | 3 | (9, 12) | empty | If I click row 1, it will pop up with frame of the ID(1), co ordinates(3

JFrame is lagging on resize

我是研究僧i 提交于 2019-12-12 00:53:04
问题 Im having a simple JFrame which draws a background color. But when i resize the window, the background color is somehow lagging, as you can see in the screenshot. Is there a way to prevent this issue? public class ToolBarTest extends JFrame{ public ToolBarTest(){ getContentPane().setBackground(new Color(221,221,221)); setSize(400,250); setTitle("Hello"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String ... args){ new ToolBarTest().setVisible(true); } }

JFrame maximized to screen size with Dimension

时光毁灭记忆、已成空白 提交于 2019-12-12 00:49:15
问题 All I can think is that I'm not setting the screen size correctly. Logs show that the height and width look correct. From the Swing trail: package net.bounceme.dur.nntp.swing; import java.awt.Dimension; import java.awt.Toolkit; import java.util.logging.Logger; import javax.swing.*; import java.awt.*; public class HelloWorldSwing { private static final Logger LOG = Logger.getLogger(HelloWorldSwing.class.getName()); private static void createAndShowGUI() { //Create and set up the window. JFrame

How to get extendedState width of JFrame

别说谁变了你拦得住时间么 提交于 2019-12-12 00:46:14
问题 I have a JFrame of which extended state option is set to MAXIMIZE_BOTH When i want to get the width of the JFrame it returns 0. so WHY? 回答1: I have a JFrame of which extended state option is set to MAXIMIZE_BOTH JFrame.getExtendedState() returns proper state When i want to get the width of the JFrame it returns 0. any coordinated are accesible after pack() is called for already visible container on the screen 来源: https://stackoverflow.com/questions/15152297/how-to-get-extendedstate-width-of