jframe

WindowListener for closing JFrames and use global variable

我的梦境 提交于 2019-12-02 07:42:26
I'm struggling with using WindowListener for closing JFrames. I have a situation where a client is logged on to a server and when the client closes his application the server needs to be informed. So in order to inform the server, another instance of a class (that handles the rmi implementation) should be addressed. that instance is a global variable in my GUI class. I searched the web a bit but all i can fined to the problem is the following structure addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { System.out.println("jdialog window closed event received"); }

Loading a .Jar Applet inside of a JFrame(Panel)

£可爱£侵袭症+ 提交于 2019-12-02 07:41:43
I'm trying to make a JFrameable "Loader" of one of my favorite Java games, but I don't know how to load the actual .Jar into a JFrame panel (I was told this was called an Applet, guess I'm behind a little bit) I have the JFrame set up with panels and everything where I want it, but I have no idea how to go about loading the .jar and sending parameters to it and telling it where i want it to be at. Any help or links would be greatly appreciated... as I can't find anything Since you haven't provided the site which is being used I'll only explain some parts. Firstly you'll need to download the

setIconImage only works in eclipse, doesnt work when exported as runnable jar file

流过昼夜 提交于 2019-12-02 07:35:56
I have searched for a while now for a fix to this. I have a project folder in my workspace (that folder is basically my root), and in it there is a file called icon.gif. In my program, I have the following: package com.mgflow58.Main; import javax.swing.ImageIcon; import javax.swing.JFrame; public class Game { public static void main(String[] args) { JFrame window = new JFrame("Guppy's Adventure"); window.add(new GamePanel()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setResizable(false); window.pack(); window.setLocationRelativeTo(null); window.setVisible(true); window

The point of origin in my GUI is off by about 25/26 pixels

梦想与她 提交于 2019-12-02 07:34:56
问题 My point of origin (0,0) on my GUI is moved up by about 25/26 pixels. So the very top-left corner of my GUI seems to represent 0,25 or 0,26. I am using a double buffer to draw in things. Basically, whenever I try to draw something in my buffer at 0,0, it appears off-screen. For example, below is a screenshot of a checkerboard pattern I attempted to generate, starting from 0,0. Although it seems fine horizontally, notice the chopped checkerboard at the top. The height is 480, which is

Serializing a JFrame and sending via network

折月煮酒 提交于 2019-12-02 07:08:02
问题 What I'm trying to do is to send a JFrame through sockets. The problem is after I send the form and press the button to view it I get the below exception. package ds3; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.ServerSocket; import java.net.Socket; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; public class SerializationApp extends JFrame { private DataForm dataForm = new

Close showOptionDialog after 5 seconds if not button is pressed in java

为君一笑 提交于 2019-12-02 07:04:51
问题 I have a showOptionDialog that ask if the user wants to delete something. I want to close the frame and not delete if nothing is press after 5 seconds. How can I achive this? Here is my code: JFrame frame = new JFrame(); frame.setAlwaysOnTop(true); Object[] options = {"OK"}; int n = JOptionPane.showOptionDialog(frame,"Do you want to delete?","Title",JOptionPane.PLAIN_MESSAGE,JOptionPane.QUESTION_MESSAGE,null,options,options[0]); if (JOptionPane.OK_OPTION == n) { System.out.println("Delete");

Modifying independent JPanels from the JFrame

久未见 提交于 2019-12-02 07:03:52
I've got a JFrame with two separate JPanels. One of the JPanels is filled with JButtons while the other has a couple of text fields. I added mouse listeners to the buttons via the JFrame and I want to make it so that when an event is fired from the first JPanel, the text fields in the second JPanel are changed. The two panels have their own classes. How would I go about doing this? Hovercraft Full Of Eels Use MVC, Model-View-Control, separation of concerns. Have the Control, which holds your listeners, change the state of the model. The Views -- your GUI's, have listeners added to them by the

JFrame (swing) switching repeating actions with buttons

两盒软妹~` 提交于 2019-12-02 06:50:31
问题 I want a JFrame application with 2 buttons (eventually more) that I can use to switch between multiple repeating actions, ofr simplicity I'm just using a console print for now, though it will probably be calling a method instead later. Here is the framework for the JFrame: public class DayNight extends JFrame implements ActionListener{ //JFrame entities private JPanel animationPanel; private JButton button; private JButton button2; public static void main(String[] args) { DayNight frame = new

Does placing setVisible() function in the beginning of the function be different when I placed it at the end of that function?

只谈情不闲聊 提交于 2019-12-02 05:59:42
I'm just new to Java GUI Programming and I'm having a problem that the components inside my panel is missing when I place the setVisible() function at the beginning of the function called by the constructor but it works fine when it is at the end. See code below: public static void main(String[] args) { new MainClass(); } public MainClass() { setFrame(); } private void setFrame() { JFrame frame = new JFrame(); frame.setSize(400,400); frame.setResizable(false); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Some area where the object of my components inside the

How to resize frame dynamically with Timer?

我是研究僧i 提交于 2019-12-02 05:55:32
问题 I'm trying to resize a window dynamically using a Timer object, but not succeeding... I set the preferred size of the panel in the constructor, which sets the size of the window nicely, though only once. The preferred size changes after the program is initialized, but the window size stays the same. Why? Because the constructor is initialized only once and therefore isn't affected by the size change? If so, how could I get around this to resize the window in real-time? I know this won't solve