Swing/AWT/SWT :: Multiple JFrames - Thread And Progress Bar
Mar 29, 2014
I'm struggling with a small project. I have 2 jFrames. The first frame has a button that...
- Display's the second frame containing a progressbar
- Starts a heavy processing thread
I need to update the progressbar on the second jFrame, from a thread started on the first jFrame.
I have 2 problems:
- How do I update the progressbar?
- When the button is clicked, an empty second frame is displayed with no controls. The controls are only rendered/shown, after the large thread process is finished...
I've attached to this post a small screenshot, showing the main idea ...
Source code:
Button action on the first frame:
private void btnGoActionPerformed(java.awt.event.ActionEvent evt) {
Progress progress = new Progress(); // The second frame
progress.setVisible(true);
clsProcess myProcess = new clsProcess(); // The thread process
myProcess.start();
In my Java SWT application, I have few methods, that take longer time to complete. These methods has to be initiate and run as response to button click. There I want to implement progress bar to show the progress/status of long run method. Long run methods are Java Processes, in which it executes some command line functionality. (ex: run ls method in Linux).
Process p = Runtime.getRuntime.exec(command)
In progress bar status is set using setSelection method which takes int as argument. How to indicate the progress of process in progress bar, because I don't have int value to pass into setSelection method of progressbar.
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();
I'm just messing around with JFrames and stuff like that (like previous posts). There is no ultimate goal here, which I realize violates that I should write everything down beforehand and know what I'm trying to accomplish. My question is, does this look ok? I'm going to start doing if...else statements but don't want to move on if I think this is bad programming. Any tips on how I create new JFrames under and if...else statement?
All I need to do is show in just one JFrame the two combined JFrames. One JFrame namely leftPanel will appear to the left or west and the other namely rightPanel to the right or east using BorderLayout. I already did creating them first as JPanels or as internal classes and subsetted them in one JFrame but that didn't work because it looked messy. And now I've created them as two separate JFrames, compiled separately, and tried to subset them as one in the JFrame. I didn't add any functionality to this program because all I intend to do is to show those two JFrames together in one JFrame. Here's the code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class dirtyIceCream extends JFrame { leftPanel westPanel; rightPanel eastPanel; public dirtyIceCream()
[code].....
What am I missing or did I code anything wrong here? Or should I use NetBeans IDE for anything as complicated as this?
I'm currently learning about Swing but I can't get my head round this piece of the code. Here is a simplified gui (not interested in the gui part but the execution)
public class SwingDemo implements ActionListener { SwingDemo(){ JFrame jfrm = new JFrame("Simple gui pro"); //rest of code public static void main(String[] args) { new SwingDemo(); }
I get the above, create a new instance of SwingDemo in the main thread which starts up the gui through the constructor. However, then the tutorial says that I should avoid doing the above but do this instead:
public class SwingDemo implements ActionListener { SwingDemo(){ JFrame jfrm = new JFrame("Simple gui pro"); //rest of code public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { //why do this instead? public void run(){ new SwingDemo(); } }); } }
Reading, it talks about an event-dispatching thread which has completely lost me... Why not just instantiate the object directly instead of creating another thread?
I have two JFrames the first one is a log in screen where i log in to the log in server that i made using RMI . If the log in succeeds i send the user object witch is Serializable to the second JFrame.
The user object is received from the server. This object contains all the information needed in the second JFrame. This second JFrame is made inside the first one and i defined a method with witch i send this user object to the second frame.
Now the problem arises , while inside this method i am able to read all the data i need from the user object. At the end of the method i save the reference of this object in a new User object defined in the second JFrame ,because i need it later on.
But soon as this method finishes , for some reason my reference to the object becomes null , and i cant use it later on.
I'm trying to get a progress bar to work on my GUI.
This is what I have so far, the parameters are taken from another class that takes in an image in packets from a Raspberry Pi and stores them to a file on PC.
public void ImageInfoReceivedHandler(int sizeOfFile) { progressBar.setMinimum(0); progressBar.setMaximum(sizeOfFile); progressBar.setIndeterminate(false);
[Code] .....
The println are printing out the correct values and they are being implemented in the methods, but nothing is happening in the GUI.
I have a thread setup in the GUI when a button is pressed
getImageButton.setText("Timer Started"); transmit = new transferImage(port); lblImgProcess.setText("Getting Image, Please Wait"); transferThread = new Thread(transmit); transferThread.start();
So the thread starts and image is then transmitted, does the progress bar need to be in that event handler?
I wish to display a progress bar during a lengthy file translation process. When I created a ProgressBar class to do this and tested it with a short test program, it seemed to work fine. But when I add my ProgressBar class to a package containing various other classes, put that package in a jar file, and then execute the class using the progress bar from a menu in my main program, the frame of the progress bar shows up with the appropriate caption but the JLabel, JProgressBar, and JButton are not displayed. I have gone over my code numerous times and checked that the ProgressBar class constructor is getting the proper arguments.
// package gov.nasa.jpl.ephemeris; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * Progress bar with message text above the bar and a Cancel button below it */ public class ProgressBar extends JFrame { private boolean _cancelled = false; private JProgressBar _progressBar = null;
[Code] ....
I have also been wondering whether I need a separate instance of the border for each panel, or whether I can just create one instance and use it for all three panels.
im having an issue with the 3rd thread that are supposed to merge the two sorted sub arrays , i pass the 2 subarrays to my runnable function sortlist and they are renamed IntSortList 1 and 2 and th1.start() and th1.join() are called and it works fine, but then i have another runnable constructor that takes IntSortList 1 and 2 but it does take a runnable. below is the code in my main,
Runnable InSortlist1 = new sortList(data2p1); Runnable InSortlist1 = new sortList(data2p1); Thread th1 = new Thread (IntSortlist1); Thread th2 = new Thread (IntSortlist2); try { th1.start(); th1.join();
I am new to threads, This is a project about 2048 game to be more accurate, and i want this project to run in this thread that i make in main...
My main:
public class Execute { public static void main(String[] args){ Display d = new Display(); Shell s = new Shell(d); Model m = new Game2048Model(); View ui = new Game2048View(m.getBoardArr(),d,s);
[Code] ....
And the error is:
Exception in thread "Thread-0" org.eclipse.swt.SWTException: Invalid thread access at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.widgets.Display.error(Unknown Source) at org.eclipse.swt.widgets.Display.checkDevice(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at view.Game2048View.run(Game2048View.java:55) //problem at Run at java.lang.Thread.run(Unknown Source)
I'm developing Chat application GUI using SWING. My GUI has two JtestAreas one for displaying message that i was sent, and another for displaying replay coming from server. I was used Thread.sleep(1000) after message sent . Due to that, AWT-EventQueue-0 thread stops to display send message in first JtextArea and waits until it get response from server. After got response from server, in one shot, My GUI displays both JtetAreas Content.
But, I need to display send Message and Response Message in two different shots. I know the reason why it displays in one shot.
i was uploading file to drop-box using java.But the problem is how can i add progress bar to file upload to drop-box.I didn't use java script for it.I didn't get any of this in drop-box API. my code is.
import com.dropbox.core.*; import java.io.*; import java.util.Locale; public class Main { public static void main(String[] args) throws IOException, DbxException { // Get your app key and secret from the Dropbox developers website. final String APP_KEY = "INSERT_APP_KEY"; final String APP_SECRET = "INSERT_APP_SECRET";
I am having a error in progress bar ... I want to see the progress upon checking the sha1 of files
This is the code:
/* * 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 program1;
Exception in thread "Thread-2" java.lang.NullPointerException at program1.ProgressBar$thread1.run(ProgressBar.java:98) at java.lang.Thread.run(Thread.java:744)
Can you have multiple key events? by that I mean say you press the right arrow key, or a number on the numeric pad, then you press the letter c. does the second key event get fired? and i can catch both events?
public static void listFiles(String path) { File[] list = null; File root = new File( path ); list = root.listFiles(); if (list == null) return; for (File f : list) { if (f.isDirectory()) {
[code]....
How would I get the overall progress of reading the directory I give to it, for example, if I give it the root directory of my computer, it would read through ALL my files and folders, and that works fine.But how would I get progress for a progress bar?
But apparently i was wrong and all i get is an empty JFrame and no Dialog. I even added my own subclass of SwingWorker in case a SwingWorker had to be created in order for a progress monitor to exist. How can I make it show?
I want a progress bar when checking the sha1 . When getting the sha1 there we see the progress of checking
here is the code
/* * 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 program1;
Exception in thread "Thread-2" java.lang.NullPointerException at program1.ProgressBar$thread1.run(ProgressBar.java:98) at java.lang.Thread.run(Thread.java:744)
I've been doing a course with a heavy focus on applets and AWT using BlueJ. I've branched out and learn to convert my applets to applications. I can successfully use frames to do similar things to applets (in BlueJ's applet viewer) but I can not seem to run more than application at a time (unlike applets where I could run several at the same time).
Below is a simple Hello World program I wrote. When I re-run main() it closes the original and starts again. (I'm aiming to explore the java.net.* libraries and for testing would like to use more than one frame at a time which can communicate to each over via sockets).
import java.awt.*; import java.awt.event.*; public class HelloWorld extends Frame implements WindowListener { public static void main (String[] args) { HelloWorld app = new HelloWorld(); app.setSize(500,500);
The below program ask the user to enter the value of x 1 , Y 1 and radius in separate boxes , What would look nice is if the user can Enter the Value X ,Y and radius in the same box.
import javax.swing.JOptionPane; public class C3E29GeometryTwoCircles { public static void main(String[] args) { // Ask the user to enter the x1 coordinate. String strNumber = JOptionPane.showInputDialog("Enter the value of x1 coordinate " ); double x1 = Double.parseDouble(strNumber); strNumber = JOptionPane.showInputDialog("Enter the value of y1 coordinate " ); double y1 = Double.parseDouble(strNumber);
So im making a calculator just basic 4 function with a clear button. as i am working into this project i am running into an issue of assigning which click sets what. For instance i click the two button how do i tell it to assign it to firstNum, versus secondNum?
private class theHandler implements ActionListener{ public void actionPerformed(ActionEvent event){ if(event.getSource()==one){ firstNum=1; } if(event.getSource()==two){ secondNum =2; } if(event.getSource()==three){ secondNum =3; }
So this for instance allows me to set one to the firstNum and then add it to two or three but im not sure what to do next. I have in my mind i want to do something like make three listener classes, that operate in sequential order like you pick the first numbers, click an operation, and then select the second numbers then hit the operation(equal) button to display answer. Am i on the right track or what?
I'm trying to create a Java swing chess application, but would like to divide the GUI part of it into at least two different classes (possibly more later, but I'm not sure yet). Currently I have a mainGUI class and a ChessBoard class, both of which extend JFrame. I want the main GUI class to contain a JPanel which will house several components, including a JPanel originating from the chessboard class that contains the actual board.
Is there any way to do this? I tried just creating a ChessBoard object in my main GUI class and then adding it to the component, but I got an illegal argument exception, because apparently you can't add one JFrame to another. How to do what I'm trying to do, or just how to split GUIs into multiple classes in general?