Swing/AWT/SWT :: How To Run Multiple Frames In BlueJ

May 27, 2014

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);

[code]....

View Replies


ADVERTISEMENT

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

Displaying Icon And Title In Multiple Java Frames?

Jan 13, 2014

I developed a simple java gui . On running a frame opens with 5 buttons and each button opens another frame when selected. There are no errors and frames open and close as required however i see that only the main program frame has the icon and title that i assigned and the frames bieng called through the buttons have the default frame with java icon and no title although it's been specified in the code of these called frames. When these called frames are executed individually though the program the title and icon are displayed.

View Replies View Related

Swing/AWT/SWT :: Possible To Stop And Start A Listener Alternatively In Java Frames?

Dec 3, 2014

I was developed a simple GUI, in that it requires modification of jtextfield content while JComboBox item selected and vice-versa. I was used itemListener on JComboBox and Document Listener on JTextField. It was gives exception while running the code. Because one listener source effected by another one..

Exceptions are like this:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Attempt to mutate in notification
at javax.swing.text.AbstractDocument.writeLock(Unknown Source)
at javax.swing.text.AbstractDocument.replace(Unknown Source)
at javax.swing.text.JTextComponent.setText(Unknown Source)
at ronanki.swing.pcahostsimUI$5.itemStateChanged(pcahostsimUI.java:368)
at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)

[Code] ......

View Replies View Related

Frames Per Second In Games

Nov 13, 2014

I have a question about Frames per second in games. In a simple game i should be able to pull off 60(exactly), right? So if i have this code for a game loop:

while(shouldRun){
Thread.sleep(1000/60);
 //loop code here
}

will that run at 60 fps?

The loop code takes a tiny bit of time, then it waits for (a second/60), so overall the code will be running overall since the code takes some time?

Is this the case , and if so is there a solution?

View Replies View Related

Support Smaller Number Of Frames Than Pages

Oct 20, 2014

I am working on this experiment code, I keep getting an exception:

run:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -256
at .MemoryManager.read(MemoryManager.java:68)
at .MemoryProcess.callMemory(MemoryProcess.java:39)
at .main(Lab3.java:29)
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

The offending line is data=RAM[physicalAddress]; inside MemoryManager.java.

why this is exactly happening and thus correct my piece of code.

The code:

main.java
package experiment;
public class Main{
/**
* @param args the command line arguments

[Code].....

View Replies View Related

How To Add Javadocs For BlueJ

Oct 7, 2014

I am new to BlueJ. I have to add Javadocs every time I finish the program, but I see a folder named "doc" .

What's that folder ? Is it Javadocs?

I see :ToolsProject Documentation => regenerate??

View Replies View Related

Calculating Factorials Using BlueJ

Oct 7, 2014

I am trying to calculate factorials using BlueJ. All of my factorials calculate correctly, I am just having an issue with something the instructor asked of us. She asked us to force the loop to stop when the user inputs "Calculate the factorial of 0", and not give any print.

So far I have my for loop with the correct conditions, I am just really confused as to how to make an if statement to stop the code when the input is 0.

View Replies View Related

Build A Calendar In BlueJ

May 25, 2014

i have a problem, i need build a calender in BlueJ. The program need to found if I put this one year have to give me the full schedule but only the first semester.

View Replies View Related

BlueJ Error Code

Apr 6, 2014

the system I am using is blue jay and java. my problem is that I have this error message pop up whenever I try to compile any of my 6 classes. Three of the classes are cities, 3 others are shops, and the final one is a inventory called Player. The following is the error code that appears when I try to compile class THshopB or class CityB.

method run in class CityB cannot be applied to given types;required: Player; found: no arguments; reason: actual and formal argument lists differ in length

A similar error occurs for the rest of my City and THshop classes,except it replaces the class CityB with CityA and occurs in class THshopA, replaces CityB with CityC when occurring in class THshopC.The public methods of CityB and THshopB are shown below, as I believe that something is wrong with the public method of one or the other. I have the code [CItyB.run();}] inside of class THshopB, and run is the part that gets the red highlight error described above.THshopB public method

[ public static void shop(Player inventory){
CityB.run();}]
CityB public method
[ public static void run(Player inventory){
THshopB.shop(inventory);]

All of my THshop classes are written in the same format, and all of my City classes are written in the same format,

View Replies View Related

BlueJ (double Input)

Jun 21, 2014

I typed the following program using BlueJ

import static java.lang.System.out;
import java.util.Scanner;
import javax.swing.JFrame;
public class Main {
public static void main (String args[]) {
Scanner read = new Scanner (System.in);
out.print ("> ");
double num = read.nextDouble();
out.println (num);
}
}

When I compile the code it gives me no errors; however when I run the program and write a floating point number it gives me the following message:

java.util.InputMismatchException: null (in java.util.Scanner)

I used to use an online compiler and the nextDouble() method worked perfectly there.

View Replies View Related

BlueJ - Creating New Variable From Within A Method

Mar 29, 2014

I am using blueJ as my java editor.

If I have a method that creates a new variable (the name of which is a string argument for the method). Can I get that variable to appear in the workspace in the variables pane?

So instead of just using return to output the variable how do I get in that variables pane?

View Replies View Related

Mirror Image In BlueJ (Java)

Sep 18, 2014

I have to mirror an image in BlueJay (java)

I have the following code, but it is missing a little bit. My instructor gave me a hint. He said that i have to use the setValue() and getValue() methods, but i'm still confused..

This code only return a black image with the same compositions as the image I want to mirror.

public Image mirror()
{
Image mirrorImage;
mirrorImage = new Image(foto.getWidth(), foto.getHeight(), "spejling");  
for(int i = 0; i < foto.getWidth(); i++)

[Code] ....

View Replies View Related

BlueJ - Generating Multicoloured Brick Wall

Nov 5, 2014

I'm trying to generate a multicoloured brick wall as part of an assignment using BlueJ.

According to the instructions we've been given, once the wall is set up and we invoke the draw() method, if we invoke the toggleMultiColoured method the bricks will go from being all read to a mix of 6 different colours...

...When I invoke the toggleMultiColoured method, however, the wall I generate is still red.

Here's the source code for the BrickWall class I wrote:

Java Code:

public class BrickWall
{
private int bWidth;
private int bHeight;
private int numRows;
private int rowLength;
private ArrayList<String> colors;
private ArrayList<Rectangle> bricks;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Multiple Key Events?

Feb 5, 2014

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?

View Replies View Related

Checkerboard Using 2D Arrays And Object Oriented Programming In BlueJ

Apr 23, 2014

Driver:

*initiating theGrid[][]*
public Zhang()
{
con.setLayout(new FlowLayout());
for (int xDimension = 0; xDimension<theGrid.length; xDimension++)

[Code] ....

All I'm getting as a blank screen and I've searched for what to put into object oriented code to make the image show up how to program using 2d arrays. I don't get any error messages (which is good I suppose) but how to make the image show up because I have stuff under the graphics and draw methods, did I do something wrong where initializing the array?

View Replies View Related

Swing/AWT/SWT :: Multiple Values In Dialog Box

Feb 20, 2014

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);

[code]...

View Replies View Related

Swing/AWT/SWT :: Multiple Action Listeners?

Oct 25, 2014

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?

View Replies View Related

Swing/AWT/SWT :: Splitting GUI Into Multiple Classes?

Sep 12, 2014

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?

View Replies View Related

Drawing Multiple Objects Swing

Jun 30, 2014

I have to do an assigment using Swing, where I have to make a Board(extends JPanel) and add multiple instances of moving elements to it, with following requirements:

By adding a new object to the Board, the others must not slow down. Also the user interface must not be blocked by the moving objects. So, the movement of the objects must be handled in a separate thread.

and

The application must support adding lots of objects, so it is not okay if every object has its own thread, as this would take too many resources. Design the application in such a way that it uses a constant number of threads, meaning that the number of threads does not grow when adding more objects.

The question is:

How to do this thing with constant number of threads?

View Replies View Related

Swing/AWT/SWT :: Using Multiple SwingWorker Threads

Aug 23, 2014

I have a Swing UI in which on click of Search button, I trigger the Search in 6 different modules in 6 Swing Worker threads. The results are returned by each Swing Worker class to the calling class.

I tried to use the below code to get the values returned from each thread. Now, I want to continue further only after all threads finish their execution. How to achieve this?

thread1.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (StateValue.DONE == thread1.getState()) {
try {

[Code] ....

I got several examples where the UI is updated direstly from multiple threads. I want the values to be returned to calling class because of below reasons:

1) When even one worker thread fails for some reason, I dont want to show the any result in the UI
2) Earlier, I was updating the UI in done() of every worker class. But, UI became inconsistent. E.g When one thread is in progress, other threads were completed and updating the UI which I dont want to do.

View Replies View Related

Swing/AWT/SWT :: Implementing Multiple Event Handlers

May 3, 2014

I'm having difficulty implementing keyboard and mouse event handlers at the same time for a program designed to notify the user when a key has been pressed or a mouse button clicked.

I can make and understand a program that does one or the other, but when I try to combine them, either the keyboard only or the mouse only works.

here is the code:

import java.awt.Color;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import java.awt.event.MouseListener;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Display And Recolor Multiple Circles?

Feb 22, 2014

I have created two classes. The FrameViewer is my driver class, and Circle is my constructor.

The first problem is, the program seems to be creating both circles, but it only displays displaying the last added circle (in this case, circle2).

The second problem is, I want to pass the color I wish to use to the constructor, but I'm having problems figuring out the proper method to do so. In the constructor, I have assigned Color.BLUE as a default. On circle two, I want to override this color choice and assign Color.Orange. I am not having any luck setting this to work either.

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
public class FrameViewer {
public static void main(String[] args) {
JFrame frame = new JFrame();

[code]....

View Replies View Related

Swing/AWT/SWT :: Add DocumentListener To Validate Multiple JTextFields

Apr 22, 2013

Code given below does real time validation for 2 JTextFields. While entering some values to txt1 and txt2 enables the save button and removing values from txt2 or txt1 reset the save button to disable. I use Netbeans as IDE.What I want to do is, enable Save button after checking multiple JTextFields for validity. If any of the text fields is empty, btnSave must be disabled.This program gives expected result up to some extent. But there is little issue. After form appears for the first time, When I type something on Textfield1, Save button enables without checking Textfield2. This happens only at the first time.

public class NewJFrame extends javax.swing.JFrame {
private Boolean isValidFromTextField1 = true;
private Boolean isValidFromTextField2 = true;
public NewJFrame() {
initComponents();
btnSave.setEnabled(false);

[code]....

View Replies View Related

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();

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Multiple Textfields Using FocusGained Event

Oct 11, 2014

I have a bunch of textboxes in a panel and I wanted to perform the same code when the user clicks into a textbox (select all the text in it). Right now I've started adding a focusgained listener to each textbox like this:

private void textField1FocusGained(java.awt.event.FocusEvent evt) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
textField1.selectAll();
}
});
}

[Code]...

Is there a way I can have one focusgained listener that all the textfields can point to but have it pick the right textfield in the textFieldx.selectAll();?

View Replies View Related







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