Using Timer To Close A Class Called By A JFrame?

Nov 26, 2014

I am making a simple battleship program, you have the menu and click Start to get the board with the bombs (4 buttons as of now) Each button has either a bomb or a defualtbutton. I created my button so it can't be unselected. The problem is I have the button in a Class.java and I want that to close in a period of time. What do you recommend using?

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package battleship;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagLayout;

[code]....

I can call the clas in my main jFrame but I want to close the class after a certain time.

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: WindowListener Not Being Called When Clicking X To Close Window

Oct 14, 2014

I have added a windowListener to my JFrame but for some reason it is not being called when I click X to close the window. I need to send a message to a server to notify it that the client window is closed. Some code snippets below (some lines excluded for brevity):

public class ChatGUI extends javax.swing.JFrame {
....
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); // I have all the window constants here but has no effect other than closing the window without calling the listener...
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
....
private void formWindowClosed(java.awt.event.WindowEvent evt) {

[code]....

This is resolved, needed to use...

addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});

... instead.

View Replies View Related

Swing/AWT/SWT :: Program Doesn't Close Though WindowClosing Event Called

Mar 25, 2014

I use the right term, release resources because after clicking the close button, the DOS prompts becomes unresponsive. So I have to close the DOS prompt, then reopen it, then type in the path again for the Java folders. Can you check where did I go wrong with my code? Is my placement of the WindowListener and WindowAdapter incorrect? Please refer to my code below:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Proj6exe1 extends JFrame implements ActionListener
{
DataOutputStream dataLabas;
JTextField rainFallField;
JButton submit;
String strRainFall;
JPanel proj6Panel;

[code]...

I have other programs where the placement of the WindowListener and WindowAdapter are as exactly like this (within the class constructor block) where they close correctly and some that behave like this, that renders the DOS prompt unresponsive.

View Replies View Related

Write A Class Called Coin Which Will Be Used By A Program Called CountFlips

May 1, 2014

i am trying to write a coin program:Write a class called Coin which will be used by a program called CountFlips.

1. The class, is an object created from this program. It is composed of data values and methods. It should contain a main method and should output the number of flips done (an integer that will be read from the user), the number of heads and tails that occur.

2. The CountFlip class will flip a coin multiple times and counts the number of ‘heads’ and ‘tails’ that result. This class should have a method called flip() of type void; a method called isHead() of type Boolean and a toString() method that will return the current face of the coin as a string.

So i created 2 classes, one called Coin.java & the other CountFlips.java,

PHP Code: package test;
public class Coin {
private final int heads = 0;
private final int tails = 1;
private int facetype;
private int flips;

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Close The Current Jframe

Sep 14, 2014

Following is the code on the click of a button, id like to know how do i close the current jframe on which the jButton4 is currently placed. I know how to send it to the next Jframe i.e JobCard. But need to close the current one. I tried using this.setVisible(true); But it does not work.

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
JobCard jobCard = new JobCard();
jobCard.setVisible(true);
}

View Replies View Related

Swing/AWT/SWT :: JFrame Close Methods?

Sep 24, 2014

I didn't know about right method for correct close operation for JFrame component or kill the object. I found out few, which of them you are using usually???

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(false);
JFrame.DO_NOTHING_ON_CLOSE.
System.exit(0);

View Replies View Related

How To Close JFrame Without Exiting Application

Apr 10, 2014

How to make a Jframe close without closing the whole operation, I started off using exit on close and changed it to hide on close and i also tried dispose on close for some reason it wont work. Here is what I have.

import java.awt.*;
import javax.swing.*;
public class GUILauncheralt{
public static void main(String[] args){
RetrieveWindow gui = new RetrieveWindow();
gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
gui.setSize(400, 200);

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Refresh JFrame When Close JDialog

Jun 5, 2014

I have JFrame and when I click a button which is in frame JDialog is opened. Now,how can I refresh JFrame when close JDoalog?

View Replies View Related

When Close Out Singleton JFrame And Then Open It Again - Components Are Gone

Nov 30, 2014

I made UpdateInmateDisplayer a Singleton so that I could access it from the private class ButtonHandler. It works to display the first inmate's number on the screen but when I close out the window and click the Book Inmate button in CurInmatesDisplayer again, it only shows a blank window. I've tried adding the components again from the ButtonHandler in CurInmatesDisplayer but it doesn't work.

View Replies View Related

Swing/AWT/SWT :: Adding Timer To Jframe

Jul 2, 2014

I am trying to write a game which needs timer beginning from zero to.... , and show it in my jframe. How can I do that?

View Replies View Related

Constructor Jframe In Class Jframe Not Be Applied To Types

Jun 22, 2014

So I have this line of code...

ioexception11.addChoosableFileFilter(new Jframe());

And when I compile it gives me...

error: constructor Jframe in class Jframe cannot be applied to given types;
ioexception11.addChoosableFileFilter(new Jframe());

View Replies View Related

Timer Class Without ActionEvent

Jul 29, 2014

I am looking for a timer class that can measure how much time has passed since the timer started (like a stopwatch). I don't wan't to use the swing timer because then I would have to create an ActionListener that increments a variable every time an event is created and that seems like too much work for the simple things I want to do. I just want it to have methods for starting the timer, stopping the timer, pausing the timer, restarting the timer, and getting the time.

View Replies View Related

Countdown Timer - Minutes Class

Dec 10, 2014

I have this code for a Countdown Timer...

Java Code:

package javaproject;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import Countdown.Timer;
import java.util.Timer;
import javaproject.Countdown;
public class Minutes {

[Code] ....

Do I need to put more code in the Countdown class or in the Minutes Class...

View Replies View Related

Stop Watch Using Timer Class Isn't Working

Jun 6, 2014

I am trying to make a stopwatch using the timer class and JButtons. When I run my program and I hit start the time stays at zero. What I want my stopwatch to do is when I press start it shows the number of seconds that have passed. The start button will then become disabled and the stop button will be the only button able to be pressed. When you hit stop it should enable only the start and restart buttons. Here is my code.

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class StopWatchPanel extends JPanel
{private final int DELAY = 1000;

[code]....

View Replies View Related

Using Nested Loops In A Class Called Print Patterns

Mar 7, 2014

Write a method to print each of the following patterns using nested loops in a class called PrintPatterns. The signature of the methods are:

public static void printPatternX(int size) //'X' from 'A' to....., size is a positive integer.

#
##
###
####
#####
######
#######
########

View Replies View Related

How To Write Instance Method For Rectangle Class Called Contains

May 29, 2014

Write an instance method, contains, that has one explicit parameter of type Rectangle. The method should return true if every point of the rectangle determined by the explicit parameter is on or within the rectangle determined by the implicit parameter. It should return false otherwise.

This is what i did so far?

public boolean contains(Rectangle other) {
Rectangle intersect = Rectangle.intersection(this, other);
if ((intersect.left == this.left) && (intersect.bottom == this.bottom) && (intersect.width == this.width)
&& (intersect.height == this.height)) {
return true;
} else {
return false;
}
}

View Replies View Related

Can't Execute Shell Script Called From Java Class

Apr 7, 2014

My java class doesn't execute a shell sript, I had given the java io file permission read and execute  over the script shell to the user who execute the java class, also I executed the script shell  in the console each RAC server using oracle user session and the srcript shell works. My team DBA told me that " The user server process is oracle". My script shell resides in all RAC server file system the last result looks as follows:

/home/mydir/dir2/mybin/compacta_archivo.sh
No Funcionando!!
java.io.IOException: /home/gi91591/reppostpago/bin/compacta_archivo.sh not found

[Code]....

of course, the script file exist on my file system, it has the suitable permission as the test result i got each time I executed on the console. My Oracle version is 11.2.0.3.0 on Rac ASM.

View Replies View Related

Java Code Using Timer Class To Schedule The Task

Feb 27, 2014

I have written the java code using timer class to schedule the task , but i am getting error as } expected, i am not able to figure out the error, I have placed the { opening and closing curly bracket everywhere but still it is giving me error.

mport java.io.*;
import java.io.FileInputStream;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.mail.internet.MimeMessage.*;
import javax.mail.internet.InternetAddress.*;

[Code] ....

View Replies View Related

Create A Class Called Dice To Represent SINGLE Cube

Apr 15, 2014

I need to work on this "Dice" program. I've done it twice already. I've also been pouring over examples on here and elsewhere online, but none of them exactly match what I'm doing, as they all say "Pair of Dice".Mine says: "Create a class called Dice to represent a SINGLE cube". It should have a method called roll() that randomly selects a number from 1-6 for the value of the dice."

It has to use java.util.random, not math.java, and it has to have numberShowing:int, roll():int, and main() all in it.The last part reads "Create a test main method for the Dice class that creates a dice and rolls it many times. Can you keep track of how many times a number comes up? Describe how or implement it in the program." I have started at this computer for hours, and read as much info as I can.

View Replies View Related

Create Class Called Factorial Algorithm Which Will Compute / Print Factorial Of Integer Number On Screen

Dec 27, 2014

1)A factorial of a number X is equal to X*(X-1)*(X-2)*...*1.For example,3! is equal 3*2*1=6.Create a class called Factorial Algorithm which will compute and print the factorial of an integer number on the screen

2)Write a Java program to accept eight integers and a search element from the user and display whether the element is found or not.(Hint:use bubble sorting and binary search)

View Replies View Related

How To Access JFrame From Another Class

Oct 9, 2014

This is my main.java:

import javax.swing.UnsupportedLookAndFeelException;
public class Main
{
   public static void main(String[] args)
         throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
   {
      Core window = new Core("GAME1", 0, 0, true, true);
   }
}
 
And this is my Core.java:

import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

[Code] ....
 
In Core.Java at line 80 how can I access window (

JFrame window = new JFrame(Game_Title); // <- this window
) ?

Also should I use throws or try and catch ?

View Replies View Related

Variable From Superclass Using In JFrame Class?

Oct 9, 2014

I would like to pass a variable I have in my main to my JFrame. In my main I calculate which pictures I should show in my JFrame. Is it possible to make objects of these pictures in my main class and use them in my JFrame? something like my code below.

public class JFrameTesting {
 public static void main(String[] args) {
Image ImageVariable = Toolkit.getDefaultToolkit().getImage("C:1.jpg");
 MyJFrame f = new MyJFrame();
f.setTitle("Drawing Graphics in Frames");

[code]....

View Replies View Related

Swing/AWT/SWT :: Using JFrame Class In GUI Designing

Jul 16, 2014

I have one question that suppose I am designing a Swing applications and I am using JFrame as Top level container.

So what is best

1)first Extends that class like

public class A Extends JFrame
{
//Do all stuff with Top Level container with gui
}

2)Or design like this from this source

[URL] ....

package components;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/* TopLevelDemo.java requires no other files. */
public class TopLevelDemo {
/**
* Create the GUI and show it. For thread safety, this method should be invoked from the event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Communication Between JFrame And Java Class?

Apr 19, 2014

I have a jFrame and a Java Class. Now i have a path of image in my jFrame which I want to display in java class(Crop2). I created an object in jFrame

Crop2 d=new Crop2();

and then I'm trying to send the data to the class file but it is not working.

View Replies View Related

Warning On Class With JFrame Inheritance (extends)

Sep 2, 2014

I'll start off by showing my full code:

Main class

import javax.swing.JFrame; 
public class groupingTest {
public static void main (String[] args) {
groupWindow test = new groupWindow();

[Code]....

At the start of the groupWindow it turns yellow and it says "The serializable class groupWindow does not declare a static final serialVersionUID field of type long".

View Replies View Related

Pass Variable In Java From One Class / Jframe To Another

Apr 3, 2015

Right so I have my ItemsPage Jframe Class and I'm trying to pass my TotalPrice variable to my CashPay so I can calculate the change. CashPrice runs and works but when I try run ItemsPage it does nothing I don't even get errors. I tried to remove that small section of trying to pass the variable to CashPay and it worked perfectly so I 100% know that's the problem. This section "public ItemsPage() { Pounds = ""; //super();

Scanner sc = new Scanner(System.in);
CashPay sendTotalPrice = new CashPay();
//System.out.println("Enter your amount");
TotalPrice = sc.nextDouble();
sendTotalPrice.printTotalPrice(TotalPrice);
"
Here is complete code for both classes, I'm using GUI builder.

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;

[code].....

View Replies View Related







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