jframe

Get Pixel Color on screen Java?

半城伤御伤魂 提交于 2019-12-20 03:09:40
问题 Hello I am trying to get the color of a particular pixel on my JFrame. This is my code. My frame is red. The problem I am having is when I click the Frame it should return me the RGB color for red that is (255,0,0) but when I click at different points i sometimes get the RGB color for white (255,255,255) what is the problem in my code guys? public class guiTest extends JFrame { private static Shape ellipse; private static Robot rb; public guiTest() { super("4-connected approach"); setLayout

How to make JFrame exist independently without parent?

一笑奈何 提交于 2019-12-20 02:57:13
问题 I am making a small application. From one JFrame, I am calling another JFrame. Now, I want this child JFrame to exist independently even after I've closed the parent JFrame. Is there any way I can do this? Or is this just NOT possible? Please help me. Let me know if you need me to post the code. Thanks. 回答1: On each JFrame, set the default close operation with #setDefaultCloseOperation to the following: DISPOSE_ON_CLOSE When you press the close-button of the frame, it will only close it and

JApplet & KeyListener

女生的网名这么多〃 提交于 2019-12-20 02:45:34
问题 I'm developing an application for my computer science classes . The task is to write a calculator but without using JTextField s or JTextArea s. I've come up with an idea of implementing KeyListener which works nice in both appletviewer and JFrame but doesn't work at all in Google Chrome (and probably other browsers). Here're my code snippets. //- BinaryCalc.java import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class BinaryCalc extends

How to check if a jframe is opened?

柔情痞子 提交于 2019-12-20 02:35:29
问题 My code below create a new array and sends it to chat(jFrame). String info1[]=new String[3]; // username , userid , userid2 are variables info1[0]=username4; info1[1]=""+userid; info1[2]=""+userid2; chat.main(info1); But i need to modify this code to work such a way that it , if the chat jframe was opened, then dont open a new jFrame .But instead open a new tab in chat jframe . The code for chat frame is : private void formWindowActivated(java.awt.event.WindowEvent evt) { JScrollPane panel2 =

Loading image in Java Code from C drive

烂漫一生 提交于 2019-12-20 02:15:08
问题 i am new to Java . i was just trying to load image as background in JFrame . What i wanted to do is get the image from C Drive(that is not my workspace) so what i did in Board.java : ImageIcon i = new ImageIcon("C:/image.png"); img =i.getImage(); and did try to paint it something like this: public void paint(Graphics g ) { super.paint(g); Graphics2D g2d= (Graphics2D) g; g2d.drawImage(img, 0, 100, null); } And then i am calling in my main class like this public static void main(String[] args)

Java Swing: main class wait until JFrame is closed

爷,独闯天下 提交于 2019-12-20 01:10:01
问题 I need some help with a simple java application which makes use of two jframe to get some input parameters. Here's a sketch of my code: //second jframe, called when the button OK of the first frame is clicked public class NewParamJFrame extends JFrame{ ... } //first jframe public class StartingJFrame extends JFrame{ private static NewParamJFrame newPFrame = null; private JTextField gnFilePath; private JButton btnOK; public StartingJFrame(){ //.. initComponents(); } private void initComponents

why doesn't the frame close when i press the escape key?

自古美人都是妖i 提交于 2019-12-19 19:03:34
问题 import java.awt.*; import javax.swing.*; import java.awt.event.*; public class displayFullScreen extends JFrame { private JLabel alarmMessage = new JLabel("Alarm !"); private JPanel panel = new JPanel(); public displayFullScreen() { setUndecorated(true); panel.setLayout(new FlowLayout(FlowLayout.CENTER)); alarmMessage.setText("Alarm !"); alarmMessage.setFont(new Font("Cambria",Font.BOLD,100)); alarmMessage.setForeground(Color.CYAN); panel.add(alarmMessage); Dimension screenSize = Toolkit

How do I set up a JFrame with a refresh rate?

家住魔仙堡 提交于 2019-12-19 12:23:49
问题 I have a 2d game which the entire structure is completely coded except the graphics. I am just updating the single component of a JFrame which is a Graphic containing 50 images. Each frame the images are in a different location hence the need for a refresh rate. To paint, I have overridden the paintComponent() method, so all I really need to do is repaint the component (which, again, is just a Graphic) every 40ms. How do you set up a JFrame with 25FPS? 回答1: This AnimationTest uses javax.swing

JFrame Close to Background and Listen to Keys

落花浮王杯 提交于 2019-12-19 11:56:09
问题 Working on a new personal project with jframe. My goal is to close the frame in an ActionListener to the background, and when specific keys are pressed ( Ctrl + Shft + L ), I want to open the frame back up. I'm not sure how I can do this keeping CPU usage low. I know I can set the frames visibility to false and then probably use a generic ActionListener for the keys however I have a few problems (and questions). Is this the best way to do it? I'm trying to keep the CPU usage as low as

JFrame Close to Background and Listen to Keys

馋奶兔 提交于 2019-12-19 11:55:58
问题 Working on a new personal project with jframe. My goal is to close the frame in an ActionListener to the background, and when specific keys are pressed ( Ctrl + Shft + L ), I want to open the frame back up. I'm not sure how I can do this keeping CPU usage low. I know I can set the frames visibility to false and then probably use a generic ActionListener for the keys however I have a few problems (and questions). Is this the best way to do it? I'm trying to keep the CPU usage as low as