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


ADVERTISEMENT

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 JFrames

May 23, 2014

I'm writing a small program in Java to simulate a shopping cart. A shopping cart has an array og objects Item. As a console application, my program runs.But, in the GUI version, I have some issues. In class MainMenu I create a ShoppingCart object, named "cart"(line 103)In class AddItemMenu I create an Item object, and I want to add it in my ShoppingCart object "cart".BUT, AddItemMenu cannot "see" variable "cart".

//MainMenu.java
package shoppingcartgui;
public class MainMenu extends javax.swing.JFrame {
public MainMenu() {
initComponents();

[code]....

View Replies View Related

Using Jtextfield On Jframe (Swing) To Enter Search Terms In Different Class

Dec 4, 2014

I have a swing jFrame set up with a control group which contains 3 radio buttons.

When one is clicked it sends its label to a jtextfield in a different class i have code parsing text by a term

Java Code:

Scanner s = null;
try {
s = new Scanner(new BufferedReader(new FileReader("/Stage_One.txt")));
s.useDelimiter("*");
String total = (s.next());
Pattern p = Pattern.compile("[]+");

[Code] ....

I just need to know how to access the jframe variables (textfields, panels and such) so i can use their inputs in code to filter a text file.

View Replies View Related

Swing/AWT/SWT :: Endless Loop While Calling Dialog Box Via Separate JFrame Class In NetBeans IDE

May 2, 2014

I've used Netbeans IDE to create a simple Swing JFrame container, class NewJFrame.

NewJFrame calls another JFrame with dialog in it. Problem is there is an endless call made to it. Here's the issue relevant piece of code:

//Code for calling class
package p;
public class NewJFrame extends javax.swing.JFrame implements ActionListener {
.........
public NewJFrame() {
initComponents(); //IDE auto generated code for binding

[Code] ....

I searched but i cannot understand why run class is getting called multiple times. I have attached the screen prints for both the screens. 2nd screen print(of called class) is very shallow since screen was blinking unstopped due to multiple calls, but i have attached a faint image of it.

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

Swing/AWT/SWT :: What Makes Java Wait On JFrame

Mar 8, 2014

With a simple "Hello World" application, once the println is executed the application exits and the process goes away.

If a simple Frame application is executed, the Frame is displayed, the println is executed but the application does not exit.

public class Frame3 extends JFrame
{
Frame3() {
setBounds(100,100,300,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[]) {
new Frame3();
System.out.println("You are here");
}
}

It isn't that Java is aware an object exists because if I create a basic non-swing, non-gui object it will exit right after the println.

Q1. What is it that causes Java NOT to exit after creating the JFrame?
Q2. What type of object(s) when created will cause the application to continue running?
Q3. What would I do if I wanted the println statement to be executed only after the JFrame was closed?

View Replies View Related

Swing/AWT/SWT :: Getting JFrame Reference Into Java Bean Using RMI?

May 21, 2014

I got a project at my university , and we are working with JBoss with the free version WildFly .And also with Java EE.

Now the application is a simple game of Battle Ships or sinking ships to be honest i am not sure as to how the game is actually called.

Registering a user and saving his or her information is not hard using a Stateless java bean , to save the data in the database.

I have a Stateful java bean for every user , the bean is created on the server side after the user succeeds in logging in to the game.

This bean is used mainly for sending an invite from one user to another , to log out the user and everything else that is needed for the user.

The main problem that i encountered here is that JBoss dose not let me have a reference on my frame inside of the bean.

This makes things hard because i would need to use a Timer to ask the bean every second or so if there is an invite from someone , and i would need to save all of the invites .

This was the only thing i could think of .And also implementing the game it self , the communication between users would be complicated more so than i think its needed.

Then my professor said that i could make a service on the clients side in witch i would have a reference of the JFrame , and i could send this service to the java bean and using this service i could get access to the JFrame making things faster.

This would make things a lot easier.For the invite and for the game itself too.

My professor explained that JBoss or WildFly is based on RMI , and he said also that i would need to set up the registry on the server side .But i got lost because i was not sure as to what should i search for .

We are using an older version of WildFly not the newest but one version older , CR1 i think.

And we are also using JPA in the Dynamic web project , server .

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

Java - Getting Data RFID Serial Rs232 In JFrame Class

Apr 14, 2014

**Getting data on from rfid scanner as Serial rs232 port in JFrame**, in this case I have made a JFrame form and I have a JTextField for storing data rfid as a String. Actually, I found a class from internet that read the RFID reader as byte, now How To get data from my RFID Class to my JTextfield Jframe in my main class as String?

Here my RFID class :

package view;
import java.util.*;
import java.io.*;
import javax.comm.*;
public class ListPorts implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;

[Code] ....

Is it possible that my RFID class merge with my Main class ?

View Replies View Related

Swing/AWT/SWT :: How To Print JFrame Content Using NetBeans Java

Sep 10, 2014

I am developing a program in netbeans forms. I've got to a point where I will click a jButton to print the content of either JFrame or JPanel. I am using Netbeans forms to develop the project....

View Replies View Related

Java Applications Communication On Different Systems

Nov 1, 2014

I'm new to java and haven't develop any application before that... I need to develop an application through which i can send data from 1 computer to another computer. These communication in between the computers are those are under one router connection. Means they can connect even without internet access

Main concept is as follow

1. Java application on computer A [server side application]
2. Java application on Computer B [Client side application]
3. Java application on computer C [Client side application]

Now computer B and C communicate with computer A. but they don't know about presence of each other

View Replies View Related

Communication Between Two Separate Java Program In Same Computer

Sep 20, 2012

I have two separate java Program that run on the same
computer : Program -1 & Program-2 .

Explain Program-1 :

Name of Program -1 is “InputFrame” that is a simple frame that contain a JTextField and a Button and a JTextArea .

Explain Program 2 : Name of Program-2 is “OutputFrame” that is a simple frame that contain a simple JTextArea that this JTextArea is a Instance object from a class with name of “DisplayFrame” .

This instance object from class of “DisplayFrame” added to frame of “OutputFrame”.Now I want run both Program 1 & 2 simultaneously in the same computer and when I enter a text in JTextField in Program-1 and after click on the Button “OK” that Text Entered in this JTextField In addition to JTextArea in Program-1 display In JTextArea in Program-2 .

I do not want use a share file between two Program-1 and -2 Or DataBase .I want if Program-1 run but Program-2 is not running and i enter a text in JTextFeild in Program-1 , after running Program-2 that Entered Text Displaye in JTextArea in Frame of Program-2 .(Offline Message) .Both Source code of Program-1 and Program-2 is Attached .

View Replies View Related

Servlets :: Java Standalone Program To JSP Communication

Aug 4, 2014

The following programs exist:

1. I have a java application which accepts bio potential data every second or two and stores it in the database. This is a socket server which accepts this data from multiple clients and spawns a new thread for processing it to store in the db.

2. I have a jsp page on tomcat server which reads historic client data from database (stored by application 1) and displays it on the page.

The socket server program in 1.) above is not running inside of tomcat server.The new requirement now is : Display all of the human data coming in live on the jsp page.Now the problem: I will now need to pass the live data from socket server (which is stand alone) to the jsp which is running on a tomcat server.

Possible solutions:

APPROACH 1: Run the socket server in the tomcat instead of stand alone and store the frequently incoming data in a java object so the jsp can access this object every second and display it on a graph.

PROBLEM : The stand alone java application does not need to be included in a tomcat server except for the fact that the jsp needs access to the live data. Also, I have read that this is not the best way.

APPROACH 2: Expose the stand alone java application as a web service and communicate with the jsp using REST architecture.

PROBLEM : The complication of using this method is that it will not have the flexibility offered by websockets or server sent events (SSE) of auto updating the latest data. The jsp will have to keep polling for new data every one second which is also not a very good option.

View Replies View Related

Java Servlet :: Two Servlets Communication With Post Method

Feb 22, 2013

We have two servlets application running on same server with Java EE 6 with below mention application URL.

Servlet1 Application URL: http://<severname>/*servlet1*
Servlet2 Application URL: http://<severname>/*servlet2*

My question is how to call Servlet2 from Servlet1 with Post method without using server name. May be something like this:

servlet.invoke(servlet2).

View Replies View Related

Java Communication With Hardware - Show Output In Numbers And Letters

May 29, 2014

I want to make project about java communication with hardware (wiz110sr) via LAN (Rj45). And for example, my hardware have ip address 198.168.0.1 ; port: 1202, connected with my PC(via lan/Rj45). I want show the output (such as numbers and letters) from my hardware in console netbeans.

When I running my code, appear :

" Exception in thread "Thread-0" java.lang.RuntimeException: Uncompilable source code
at mypkg.startListenForTCP$1.run(startListenForTCP.ja va:48)
at java.lang.Thread.run(Thread.java:745)
BUILD SUCCESSFUL (total time: 1 second) "

Here's the code :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import sun.rmi.runtime.Log;
 
[Code] .....

View Replies View Related

Java Socket - Client-server Communication Stuck With Multi-threading

Feb 6, 2015

Firstly, my code is just a demo of my multiplayer game (2 or more players can play simultaneously) to demonstrate my problem without any extra things. I have successfully implemented peer-to-peer (P2P) communication in my game. Later, I decided to add support for client-server communication (ie a central server which is also a player) in my game. It should be much easier than P2P. Now here is the problem:

Suppose, I have 1 server and some clients (may be 1 or more clients). They all should give the following output:

Starting...
A
B
C
E
F
...
...
Done!

They all give the above output without using multi-thread. But using multi-threading, it gives the above output only when there're 1 server and 1 client. I'm using 2 threads (1 for sending, 1 for receiving) for each Socket. That means, each client has only 2 threads for communication but the server has (2 * totalClients) threads.

I've attached my full test project. So, here I'm only showing my 2 thread classes.

ReceiveThread class:
class ReceiveThread extends Thread {
private ObjectInputStream receiveStream;
private BlockingQueue<Character> queue = new ArrayBlockingQueue<Character>(Common.totalClients);

[Code] ....

Since I've attached my full test project, I'm not showing the other 3 classes. They are ServerMain, ClientMain and Common. If I've 2 clients to be connected, then I get the following output:

Server: (Runs first)

Starting...
A
Client 1 (clientID is 1): (Runs after the server)

Starting...
A
B
B
Client 2 (clientID is 2): (Runs after Client 1)

Starting...
A

They are stuck at there, even no exception. Actually, the server and the clients are stuck at the line try { ch = queue.take(); } if more than 1 client are connected. It seems that all are trying to receive data. But without using the dedicated threads, they all work as expected even for more than 1 client. Why is this behaviour? How to solve it? Note that I have used the same SendThread and ReceiveThread classes by which I have succcessfully implemented P2P communication.

About my attached test project file:

It has 5 small .java files for the classes as stated above. It is currently faulty when using additional threads. You have to change clientID variable for each client (they are described inside). But it works as expected without additional threads. To test it without the additional threads:

Comment " TODO" linesUncomment the single lines just after " TODO" linesComment the additional thread construction lines (4 lines)

Currently, for a workaround, I'm not using the dedicated threads for sending and receiving data only for client-server communication in my multi-player game. But I'm still using these threads for P2P communication. I don't know why it is and how to solve it.This is the attached test project file as described above.

Attached File(s) : Test Project.zip (4.11K)

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 :: Add A Rectangle To JFrame?

Apr 13, 2014

Is there a way to simply slap a rectangle into a JPanel (make it appear) with out creating an inner Class or helper Method, all within "Main"? And if not, why?

Making a JFrame is easy.

Adding a JPanel is a snap.

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TheJFrame {
public static void main(String[] args) {
// TODO Auto-generated method stub

[code]....

View Replies View Related

Swing/AWT/SWT :: Java GUI With Separate Class For JList - Adding Items To The List?

Sep 19, 2014

I am trying to create a GUI interface in swing which consists of four classes: a GUI class, which creates a main JPanel, a label, and a JList, which it takes from the second class, a MovesList class that contains a JList and the stuff needed to interface with it. It also has a main class, which basically just creates an object of the GUI class for the main window, and an Other class from which I would like to be able to add an item to the JList. I created methods in the MovesList class to get each component (like getMoveslist, or getMovesListScrollPane), which I then used to create the JList in the GUI class. I also created an addMove method so that I can add an item to the JList from any class through a MovesList object. However, this addMove method only works when called from the GUI or MovesList classes -- it does nothing when I collect from the Other class.

Here is my code:

//Main class
public class TestProject {
public static void main(String[] args) {
GUI mainWindow = new GUI();
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

[Code] ....

When I run this code, I get a window with a JLabel that says "Moves," and a JList that contains five elements -- test 1-test 5, but not a sixth "test from other class." ( using the add move method ) However, when I click on the window, the addMove method is also called, and successfully adds "test 6" to the list.

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

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 View Related

How To Use JFrame In Child Class - Two Extend Calls

Feb 4, 2014

I am working with a program where I am required to use a JFrame in a child class. The only way that I know how to access a JFrame is to do, example (public class Example extends JFrame), but since it is already extending the parent class, I am kind of stuck. I do not think that you can extend two separate classes, so..... I am stuck.

View Replies View Related

Difference Between Extending JFrame And Just Creating One In The Class?

Oct 18, 2014

What is the difference between extending JFrame in one class and simply constructing a new JFrame object in that same class? What benefits do I have with each solution, providing I want to use that class to create the GUI. Is it the same or are there differences rather than not having to reference to a new JFrame to be able to use its functions?

View Replies View Related

Swing/AWT/SWT :: JPanel Inside A Jframe?

Apr 9, 2014

I have a Jframe and i want to add inside 4 different jpanel.This is easy.

what is difficult is how can i change them dynamically with 4 other new jpanels and 4 other new jpanels?

I have try with BorderLayout but not working.

It's a wizard like but not the same.

I have a jpanel with jbuttons jpanel with a jtable jpanel with textarea and jpanel with jlabels. All this have to change with other 4 jpanels, where to look?

View Replies View Related







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