jframe

Dispose JFrame from another class

偶尔善良 提交于 2019-11-28 02:27:22
How can I dispose JFrame from another class? My code is listed below. I use Netbeans generate form for generate window. And I want dispose using another class(name is needDispose). public class needDispose { /** *Call for dispose frame */ public static void disposeMyFrame(){ myEasyFrame.getMainFrame.dispose(); // DOESNT WORK } } NETBEANS GENERATE (important method is getMainFrame() ) import javax.swing.JFrame; public class myEasyFrame extends javax.swing.JFrame { /* * Get frame */ public final JFrame getMainFrame() { return this; } /** * Creates new form myEasyFrame */ public myEasyFrame() {

Print the whole program layout

大城市里の小女人 提交于 2019-11-28 02:25:41
I have made a Java program ( JFrame based) using Netbeans, I would like to know if it is possible to print the layout of the program I wish to have a button and set the function to "print" and the final layout of the frame will be printed, is it possible? If yes, any reference source? This will depend on what it is you hope to achieve. You could simply print the contents of the frame to a BufferedImage . This allows you to control what you want to capture, in that you could print the content pane instead of the frame. You could use Robot to capture the screen. This will capture what ever is on

Embed .swf file to my Jframe

浪尽此生 提交于 2019-11-28 02:24:28
I'm having a problem in adding my swf file to my jframe. They say that i should try the JFlashplayer but it is only a trial one. Can you give me some sample code for this? Here is my flash player adapted from the example on their website. BCFrame is essentially a JInternalFrame. You can have it extend whatever. It will need slight modification to work, but should be strait forward. You can rip out anything that doesnt exist. Other possible solutions are: jffmpeg - do a search for it http://www.humatic.de/htools/dsj/samplecode.php?WebM.java http://code.google.com/p/gstreamer-java/ http://www

Java - adding components to JFrame

a 夏天 提交于 2019-11-28 02:12:39
问题 I've seen a couple of ways of doing theism they both seem to work but I'm just wondering if one is better practice over the other. For example, with a JFrame called myFrame you could do: myFrame.add(new JButton("OK")); And you can also do: Container c = myFrame.getContentPane(); c.add(new JButton("OK")); Is one of these 'correct'? 回答1: A literal copy from the class javadoc of JFrame The JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-level containers, a JFrame

How To Call JFrame from another Java class

ε祈祈猫儿з 提交于 2019-11-28 02:11:56
I am trying to do a simple Jform and call it from another class. I want to use this Jframe in a server client application, but I don't know how to open the JFrame class from another class. Like user has to chose 1- to open Jframe. 2- To Exit. So What am I doing wrong? Below are the codes: Jframe Class named Calculas.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author user */ public class Calculas extends javax.swing.JFrame { /** * Creates new form Calculas */ public Calculas() { initComponents(); } /** * This method is called

How to make a thread not freeze you whole JFrame. JAVA

亡梦爱人 提交于 2019-11-28 01:44:51
Hey i just need a question answered... How would i make the following code not freeze my whole JFrame? try { Thread.sleep(Integer.parseInt(delayField.getText()) * 1000); System.out.println("Hello!"); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } use a different thread to perform this task. If you do this in the main UI thread then it will freeze.. For example you can do following new Thread() { @Override public void run() { try { Thread.sleep(Integer.parseInt(delayField.getText()) * 1000); System.out.println("Hello!"); } catch (InterruptedException ex) { Thread

Confusion with the Java Swing Timer [closed]

久未见 提交于 2019-11-28 01:43:14
I am really confused with the Java swing timer. Does it need an action listener? Could someone please give me an example? Thanks! Here is an example of using javax.swing.Timer : import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.swing.Timer; public class SimpleTimer extends JFrame { private JLabel label; private Timer timer; private int counter = 10; // the duration private int

How can my ActionListener for a JButton access variables in another class?

狂风中的少年 提交于 2019-11-28 01:19:24
I am doing a slot machine for a project. I am having trouble getting my JButton to generate new random numbers from my ArrayList . I can randomize the numbers when the program starts and have an actionlistener set up, but it doesn't do what I need. It was merely for testing purposes. My Actionlistener is in a different Java file. Everything works, I just can't figure out how to generate new randoms in the placeholder of plc1 , plc2 , and plc3 when the button is clicked. I have just recently began to really code as about 3 weeks ago. No haters please, this is my first project ever. package

Java - Message when closing JFrame Window

做~自己de王妃 提交于 2019-11-28 01:16:08
问题 I have a Java Program containing a class Application inheriting from JFrame. I want to display a message which asks the user if he wants to exit the program upon clicking the X button at the top right of the window. This is my code so far: I got this code from a tutorial I found online. I coded the WindowClosing event handler myself. However, I have trouble registering the window listener (addWindowListener). It is telling me that WindowAdapter is abstract and cannot be instantiated. How can

Position on Screen Right Bottom

北战南征 提交于 2019-11-28 01:12:14
I need to position JFrame on my screen. But I can't make them appear on the right side of the screen bottom. Please can someone explain me how to position them, if you can describe how to do it, it would be great. Here is the code so far. //Gets the screen size and positions the frame left bottom of the screen GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int)rect.getMinX(); int y = (int)rect.getMaxY()- frame.getHeight(); frame