Swing/AWT/SWT :: How To Prompt Before Exit In Single Frame Application

Apr 22, 2014

I have a Single Frame Application and I simply want to prompt the user with a dialog confirming they really want to close before they actually close the program, specifically when they click the X in the upper right. I THOUGHT it was like any other java application, with the slight added complexity of having to target the program-created-JFrame with: ".getApplication().getMainFrame()".

MyApp.getApplication().getMainFrame().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

With that code, DO_NOTHING_ON_CLOSE is set on the JFrame, yet the program closes anyways. Which I don't understand.So I did some reading and found this: URL....That lead me to the configureWindow override, where I successfully tried this:

root.addWindowListener(new WindowAdapter() {

@Override
public void windowClosing(WindowEvent e) {
// write your code here
System.out.println("Window Closing");
}
});

But as far as I can tell that will only let me react to the window closing, not to the command to close it, where I could then kill the command in the dialog if they so "no I'm not ready to quit yet", if that makes sense. So, how to give a prompt before closing?I am using netbeans IDE to create this app - not sure if that is relevant, since maybe it is an oddity with the IDE and not Single Frame Applications.

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Panels Switching On A Single Frame Using Netbeans Builder

Feb 3, 2014

I am writing a ComputerBaseTest application with Netbeans. I have each question on a panel and I want the questions(panels) to be switched, viewing the previous and the next question on a single frame, but I do not know how.

I only understand frame switching if each questn is to be on a frame but each score on each question (frame) do not sum up to give the overall score at the end of the test. Using multi-frame shows a sign of bad programming.

View Replies View Related

Swing/AWT/SWT :: Unable To Add Jpanel Dynamically Inside Single Frame

Oct 4, 2014

I am building a GUI application which consists of two panels "panel" and "panel1". "panel1" have a button "addTimer" when clicked it should add the "panel" to the frame if i gain click the button it should again add the "panel" without overlapping the previous "panel" rather it should be created below the previous "panel". If i click on the button "addTimer" n times it should add the panel n times. Along with this the frame size has to dynamically change depending on the number of panels produced. Below is the code i tried my level best to satisfy the above conditions.

package superTimerV2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SuperTimer extends JFrame {
private static final long serialVersionUID = 1L;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Application That Displays A Frame Containing Two Panels

May 9, 2014

I'm having trouble with this program. In my textbook it says "Write an application that displays a frame containing two panels. Each panel should contain two images (use four unique images - your choice). Fix the size of the first panel so that both of its images remain side by side. Allow the other panel to change size as needed. Experiment with the size of the window to see the images change orientation. Make sure you understand why the application behaves as it does". I successfully imported the images, but I can't find out anywhere how to allow the second panel to change size with the window.

import java.awt.*;
import javax.swing.*;
public class TwoPanels
{
public static void main(String[] args)
{
JFrame frame = new JFrame ("Embedded Images");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon iconOne = new ImageIcon ("glove.jpg");
ImageIcon iconTwo = new ImageIcon ("cleats.jpg");
ImageIcon iconThr = new ImageIcon ("bat.jpg");
ImageIcon iconFou = new ImageIcon ("baseball.jpg");

[code]...

View Replies View Related

Multiple Frames In Single Frame

Apr 3, 2014

i want to know how i can add more than one frame in a single frame means main window or frame will be constant and only components will be chang or vary as in a software or game .

View Replies View Related

Adding Multiple Components To 1 Single Frame / Panel

Apr 15, 2014

Title says it all i want to get these two components:

Java Code:

package TestVersion;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

public class GameWorld extends JPanel {

private int charX = 225;
private int charY = 225;
private int charDiameter = 25;

[code]...

View Replies View Related

Swing/AWT/SWT :: Slot Machine - GUI Exit Button

Mar 13, 2014

I've spent ages trying to implement an exit button into this code. Its the start of a GUI for a slot machine, the actual machine code is in a separate class and I haven't linked them yet. My question is where/how would the exit button be added? I've tried and failed a lot of times....

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SlotMachineGUI
{
public static void main (String[] args)
{
//create new jframe
JFrame frame = new JFrame ("Slot Machine");

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Frame And Panels

Nov 30, 2014

I wrote the following code to get a frame,button in south and a red color circle,which i got.In the "actionPerformed" method i wrote "setContentPane(mp2)" thinking it would put another panel on the frame with a blue circle but when i pushed the button,the button got stuck and the circled did not change.

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Fra implements ActionListener
{
MyPanel2 mp2;
JFrame frame;
JButton button;
public static void main(String[] args)

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Paint Image On Frame

Mar 8, 2015

I simply want to paint an image on my frame, just once each time the paint() method is called, but how to call the paint method in any good way. This is how it looks:

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

[Code] ....

I have a frame in another class, and from my assumption I need to somehow tell my paint method to paint on that specific frame right?

View Replies View Related

Swing/AWT/SWT :: Java Frame Is Showing Blank?

Jul 5, 2014

i have problem with the following two java classes, driver class Reservations and Room class. When i run, it just show blank frame, tell me where i gone wrong.

import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
public class Reservations extends Frame implements ActionListener {
Color lightRed=new Color(255,90,90);
Color lightGreen=new Color(140,215,40);
Rooms room=new Rooms(5,3);

[code]...

View Replies View Related

How To Avoid Flickering When Calling Another Swing Frame

Jul 28, 2014

I am trying to call another swing frame from my current frame. And after calling second frame i dispose the current frame.

But while second frame coming on the screen, current frame gets dispose and second frame takes some seconds to appear on screen.

So its creating a bad flickering effect on screen and its not suitable for my application.

I want that first frame will call sencond frame and it will not look like second frame is called. I just want to cancel flickering effect.

Here is my source code.

1st Frame:

public class Welcome extends JFrame {
JFrame f;
JTextArea nameField,nameField1;
JLabel lable;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Jinternalframe Active Frame Different With Java 7?

Jun 24, 2014

I am in the progress of updating my code and re-testing after switching from Java 6 to Java 7. When I open multiple JInternalFrames in my application under java 6 I am used to closing the top most internal frame and having the frame immediately under it become the next active frame. When I run the same code under Java 7 I see a different behaviour in as much as when I close the last frame I opened, the next one to become active is the first one.

To illustrate this another way, lets say I open 5 internal frames, 1,2,3,4 & 5

In java 6 when I close frame 5, frame 4 becomes the active frame.

In java 7 when I close frame 5, frame 1 becomes the active frame.

View Replies View Related

Swing/AWT/SWT :: How To Generate PDF File Of The Contents In AWT Frame

Sep 25, 2014

I have been doing a project of ERP solution using JAVA AWT FRAMES and MYSQL(for database purpose). Here there is an ADMIN portion, who has the authority to make PAYROLLS of individual employees. There is a Frame where individual employee details will be shown(like basic salary, HRA, no.of leaves, other allowances...etc) in text boxes.

Now what i want is to make a PDF file of that payroll, so that I can make a hardcopy of it. The idea is just like anyother online form fill-up, where at the end you submit and save (or export) as a PDF (or text file) document. But I mention that it is a stanalone project, not an online one (i think it doesn't matter though).

So the basic idea is how to make a PDF file by extracting the text field or choice contents from a frame in JAVA AWT.

View Replies View Related

Java Swing Frame Can't Call On Other Methods From Main

Mar 25, 2015

I am trying to make a 2d graphical animation using the java swing classes in order to make a frame. I had a basic version working when all of the code was under the main method, but when I moved some into another method it broke it. With y understanding of java my code should work as I create a variable of the method containing the code and then assign the size and exit button. However this causes many problems such as my BeaconFrame method informing me that it is unused when I have used it. Here is my code:

import javax.swing.*;
import java.awt.*;
 public class BelishaBeacon {
  public void BeaconFrame() {
JFrame frame = new JFrame();
JPanel panel1 = new JPanel();

[code]....

View Replies View Related

Swing/AWT/SWT :: Listener Called Multiple Times On Single Click?

Jan 30, 2015

I have the following listener on a tableset of names:

ListSelectionListener singleListener=new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int row=e.getFirstIndex();
if (row==previousRow) {
row=-1;

[Code] .....

The println shows that getValueIsAdjusting is called 4 times when I click a single selection from the list. Is this normal behavior? If so how do I determine which call to really use. If not, where can I look to see why it is being called 4 times on a single click?

View Replies View Related

Swing/AWT/SWT :: Detecting Mouse Click Inside A Box Painted In Frame?

Feb 9, 2015

In the method mouseClicked(MouseEvent me) the co-ords of the click are obtained.

* if they are within the confines of the rectangle rect, console output System.out.println("inside box") is displayed
* in either case the click co-ords are displayed in the console

I'm getting the co-ords of the mouse clicks but no message when the click is inside the box

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/*
Experiment 04 was successful. So now (Experiment 05) I must try and see if I can identify mouse clicks that occur within the rectangle.
*/

public class AFrame extends Frame implements MouseListener {
ARectangle rect;
public AFrame(ARectangle rect) {

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Fitting Dynamic JTable Inside A Dialog Or Frame?

Apr 22, 2014

I want to calculate the height of a dialog that contain only a table depending on how many rows that table it has so I'm using the cross multiplication rule.For example i check initially that my table is well fitting into the dialog(Without space at the bottom) for some value and after that i use the cross multiplication rule because data are dynamic.But unfortunately this rule does not solve the problem.What's the best rule for fitting a dynamic table inside a dialog or a frame? Here is my code.

public class FlowLayoutChangingGap {
public static void main(String[] args) {
// just for testing perpose but data are getting from database and it's dynamic
Object[][] data = {
{ "Kathy", "Smith", "Snowboarding", new Integer(5) },
{ "John", "Doe", "Rowing", new Integer(3) },

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Paint Circle In Frame On Key Press - Cannot Get KeyListener To Work

Nov 3, 2014

I wanted to try out using a KeyListener to read what key I press so it can paint a circle in my frame, but I can't get it to work?

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Hangman Game - No Graphics Show Up On Eighth Guess (Blank Frame)

Feb 5, 2015

I'm having some problems with the graphics of my hangman game. The graphic that's supposed to show up on the first guess (the hangman pole) doesn't show up until guess number 2. And on the eighth guess, no graphics show up (I just get a blank frame).

import java.awt.*;
import javax.swing.*;
public class HangmanFigure extends JPanel {
private int guesses;
private Image background;
public HangmanFigure() {
super();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Runtime Localization Of Swing Application

Mar 19, 2014

I would like to be able to change the locale in my Swing application at runtime and have all the text elements on the GUI update themselves with localized text from a ResourceBundle of the new locale.If there a simple way of achieving this without having to create an event model for all GUI pages?

View Replies View Related

Best Way To Run A Swing Application On The Web?

Sep 13, 2014

What is the best way to run a Swing application on the web? Should I convert it to an applet or do something else?

View Replies View Related

Exit Program When Nothing Is Input

Apr 16, 2014

If a user inputs nothing the code should end ... How Should i do it?

import java.util.Scanner;
public class MyQueue<T> implements Queue<T> {
private T[] ringbuffer;
static int capacity = 0;
int mysize = 0;

[Code] ....

View Replies View Related

Execution Of Swing Application On Another PC

Apr 6, 2014

I am writing a Java Swing GUI application on my pc. I have to give this application to my cousin with another pc, where he is not aware of programming. then how can he execute that application? are there any ways of skipping the "javac" and "java" procedures while executing the app on his computer?

I am using win7 x86 and same at my cousin's place. I am also using eclipse-kepler sr1 ide for app development.

Are there any easy ways of automating this "javac" and "java" process(compilation and execution)? something like...scripting?

View Replies View Related

How To Input Exit Code Into Program

Mar 12, 2014

I just want to know how I can get my program to end when the user inputs "0." By using: System.exit(0);

import java.util.Scanner;  
public class TestCode
{
public static void main (String [ ]args ) {
Scanner console =new Scanner(System.in);
System.out.println("To exit program input 0");
for (int y = 1; y < 11; y++ ){ // Executes output 10 times
 
[code]....

View Replies View Related

Allowing User To Input Until They Want Exit

Aug 18, 2014

/* Jessie Garza
* 08 / 18 / 14
* ModCalculator
*/

import java.util.Scanner; // program uses Class Scanner
import javax.swing.JOptionPane;
public class ModCalculator
{
// main method begins execution of Java application

[code]....

I am having troubles with allowing the user to input operations/digits until they want to exit, I have tried looping, but I was unsuccessful, came here hoping to figure this out.Currently I have it ending with Break statements after each switch so that they don't coincide all together.. I can't figure out how to keep the Break statement AND loop to previous code of System.out.println( "Please enter an operand which you would like me to calculate with :");

String st = input.next();
c = st.charAt(0);
System.out.println( "I will need for you to input two integers and I will output the result.");
System.out.print( "Enter first integer to calculate: " ); // prompt
number1 = input.nextInt(); // read first number from user
System.out.print( "Enter second integer to calculate: " ); // prompt
number2 = input.nextInt(); // read second number from user

and allowing it to run through the rest of the program with the options still in tact, while having an if statement of an exit keyword.

View Replies View Related

Swing/AWT/SWT :: Application Just Stop Itself During Execution

May 18, 2014

I made a check4 application with Java.It correctly works but sometimes the application just stop itself during the execution.I never had a problem like this. The application just stop itself and i can't even quit using the closing button..

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved