Get ActionEvent When Change JFrame Size?
Apr 8, 2014
I wanted to make a program that would change the color of a circle when I click a button. The problem is that the circle also changes color when I manually change the size of the frame with my mouse. For some reason it trigers an ActionEvent, and i don't know why.
My code is the following:
Java Code: import java.awt.*;
import javax.swing.*;
public class MyFirstGui implements ActionListener {
JFrame frame;
public static void main(String[] args){
[code]....
View Replies
ADVERTISEMENT
Jan 14, 2015
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
[Code].....
View Replies
View Related
Feb 4, 2015
I built a GUI and after testing it on various platforms I think I would like to make it bigger by a factor of 2.2 or so.
Is there an easy way to just enter the factor 2.2 and have the GUI change by that factor?
I have over 50 components in the GUI. Ideally each one would just enlarge by the factor including the fonts.
This was my first (and only so far) java program. I didn't know anything about layout managers. I used netbeans and it generated all the code.
View Replies
View Related
May 26, 2014
I am rather new to Swing, and I am building a game right now in which I need to display a pop-up window as a reminder for what commands exist within the game. I created a class extending JFrame for this and added all the information I need. However, for some reason, no matter how many different ways I try to set the size of this window (setSize(w, h), pack(), using a different layout, adding the compnents to a JPanel first and setting the preffered size of that, then adding the JPanel to the JFrame), it doesn't work. Instead of a window of my requested size, I get a tiny, maybe 100 x 100 pixel window that needs to be resized in order for its contents to be visible.
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
[code]....
View Replies
View Related
May 2, 2014
I am having trouble while printing out form. So far I have succeeded to print it out.But my question is that I want jpanel to print out in Landscape rather then portrait.
View Replies
View Related
Apr 13, 2014
I have a simple application where I display a JFrame. I want to maximize the JFrame size, so I have the code this.setExtendedState(MAXIMIZED_BOTH); in the constructor. How do I find the dimensions of this JFrame in its extended state though? I tried this.getSize().Height , this getSize().getHeight() and this.getHeight()? None of them work because they just return a value of 0. And what is the difference in all these statements in terms of what they do?
View Replies
View Related
Feb 10, 2014
So, I have a game. I would like to make a game where you press "start" and THEN it starts. Also, I want to have collision with triangles, not just squares. The way I handle collision right now is with if statements, if the object is within the other, game over.How would I do collision with triangles? Lastly, how do I set a high score? how to change fonts and font size in swing?
View Replies
View Related
Jan 19, 2014
I'm using a jpanel with an 8 by 8 grid layout of jlabels to which I'm adding images to represent a chess board. At first, I was using the ImageIcon class to initialize my icons, but as soon as I added these icons to the labels, the labels no longer changed size with the window (which I want to happen). URL...
So I copied in the class, and initialized a different set of icons using the stretch icon class (specifically, the method that allows you to initialize a stretch icon from a filename), however, when I use these stretch icons, the result is the same. Is something wrong with the class, or with my implimentation of it, and how would I fix this?
View Replies
View Related
Jan 13, 2014
package name;swing library found in javax called to use the graphical contents.
import javax.swing.*;
//creating the contents for the calculator
public class calc {
JButton btn1= new JButton("1 ");
JButton btn2= new JButton("2");
JButton btn3= new JButton("3");
[code]....
I have tried different sizes for the 'TextField' but when I change the size, the position changes instead of the size itself.
View Replies
View Related
Jan 16, 2014
I'm using a jpanel with an 8 by 8 grid layout of jlabels to which I'm adding images to represent a chess board. At first, I was using the ImageIcon class to initialize my icons, but as soon as I added these icons to the labels, the labels no longer changed size with the window (which I want to happen). Someone suggested to me to use this custom stretch icon class, found here:
[URL] ....
So I copied in the class, and initialized a different set of icons using the stretch icon class (specifically, the method that allows you to initialize a stretch icon from a filename), however, when I use these stretch icons, the result is the same. Is something wrong with the class, or with my implementation of it, and how would I fix this?
View Replies
View Related
Feb 20, 2014
I'm trying to create a chess program in java swing, and for the board I'm using an 8 by 8 array of jlabels stuck inside a jpanel with a grid layout. I would like the board to change size when the window changes size, and the grid layout accomplishes this succesfully, until I add the actual icons to the jlabels. Then the board just stays a fixed size. Someone suggested I use their "Stretch Icon" class, found here:[URL] ...., so I tried initializing the icons using one of the constructors in the class (the one that takes an image name and a boolean value for whether or not you want the resisizing to be proportionate (to maintain the aspect ratio)). However, the same thing happened. The board appears, but it does not resisize. To attempt to fix this problem, I tried simplifying my code, reducing the program to two jlabels within the jpanel, for which I then tried to set the image in the same way. Here is my simplified code:
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
[Code] ....
I'm misusing the stretch icon class, or just generally what's going wrong/how to fix it?
View Replies
View Related
Aug 13, 2014
I would like to detect when the user change de JFrame. I make:
public class UI implements ActionListener, ComponentListener, DocumentListener, MouseListener{
private JFrame ventana;
private JTable table;
private JPanel panel;
private JScrollPane tableScrollPane;
[Code] ....
I put componentResized but when I change JFrame I cant see the string that I put in the method.
View Replies
View Related
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
Apr 8, 2014
I am trying code that When i press a button(New user), i want the event to send me to a new windows that i have created in Scenebuilder... I dont know why it wont work, i get this exception:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
[Code] .....
My controller.
package controllers;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
[Code] ....
The main windows does work, but just when i press the button i get that nasty exception...
View Replies
View Related
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
Jan 23, 2015
how we call a jFrame from another jFrame .
View Replies
View Related
Jul 6, 2014
Can be :
results = null;
results = new double[2];
results = new double[50];
results = new double[100];
How determine size of this table : System.out.println("table size=",???);
View Replies
View Related
Apr 5, 2014
I am asked in my assignment to make a program that accepts a text file as an example a novel and i have to sort each word as a PERSON or ORGANIZATION or LOCATION or O as in Other , example :
Microsoft/ORGANIZATION ,/O Nelly/PERSON !/O '/O
Now we notice that microsoft is and organitzation and "," is Other and Nelly is a person's name and so on ..
Now I am asked to return the numbers of tags in the text which is 4 in our case because we have (ORGANIZATION,PERSON,LOCATION,OTHER)
My question here is my logic true ? And since i made a map of String,String ; Is there any way that i can get the size of the values in our case the values are the organization etc.. ?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
[code].....
View Replies
View Related
Mar 11, 2015
class Father
{
public int a=5;
private int b=10;
[code]...
what is the size of obj from above code?
View Replies
View Related
Apr 23, 2014
I am just not sure of some theory in collections, ArrayList and LinkedList maximum capacity depends on the memory allocated to the JVM. But according to few people those list has a maximum capacity of Integer.MAX_VALUE.
According to my experiment, those list has a maximum capacity of Integer.MAX_VALUE since the get method of List accept a parameter of int primitive type (index of element), therefore we can conclude that the maximum capacity of List is equal to Integer.MAX_VALUE.
But what about the Map? get() method of map accepts object(the key of the map). So does it mean that the maximum capacity of Map depends on the memory allocated to our JVM? Or its maximum size is Integer.MAX_VALUE also just like Lists and Arrays? Is there a way to prove it? Is Map designed to hold infinite number of data (disregarding the heap memory space exception)?
And also about Stack, Deque? is it also the same as Map (in terms of maximum capacity)?
View Replies
View Related
Mar 2, 2015
Java Code:
import java.awt.*;
import javax.swing.*;
public class addImage extends JFrame {
private ImageIcon img1;
private JLabel label1;
private ImageIcon img2;
private JLabel label2;
[Code] ....
I want to decrease the size of image 2 but code on line 18 is not working why????
I have attached the output ....
View Replies
View Related
Feb 15, 2015
I have the textfile which has lines:
A B 2 midterm 100
C D 1 final 90
C D 1 midterm 90
A B 2 final 80
**NO ARRAYLIST IS ALLOWED!** And the textfile is passed into the method. How to get the size for the array non-randomly inside the method from the passed Scanner file?? What if you have lots of numbers of lines, so how could that be done?
I have doubts about this line Exam[] object = new Exam[12];
Java Code:
public static Exam[] readAllExams(Scanner s) throws ArrayIndexOutOfBoundsException
{
String firstName = "";
String lastName = "";
[Code].....
View Replies
View Related
Oct 8, 2014
ArrayList l = new ArrayList();
System.out.println(l.size());
When I running the above code in eclipse the console show me the result as "0". So how to rectify this code to find default size as 10.
View Replies
View Related
Feb 28, 2014
I am using JSF 2 & Richfaces 4
My input text box should accept only 1 character.
<h:inputText id="empid" value="#{details.val}" size="1" />
Set the size as 1, still it showing more size in the screen.
Apart from size =1, any other place to set the size of the text box?
View Replies
View Related
May 7, 2013
Is it possible to compare 2 arrays as below if they have same size?
Int array[][] = new int[10][10];
array1[I] == array2;
Or assign the whole array to another array?
array1[I] = array2[I];
Suppose I have 2 arrays, 1 is old, and 1 is new.
I will do the calculation to update the new array.
Then, I will compare between the 2 arrays.
If they are the same, I will stop the calculation.
If they are not the same, I will assign the new array to the old array.
Then, I will do the calculation again until the old array and the new array are the same.
As I do not want to write a loop to compare and assign the value to the arrays. May I compare or assign the values to the whole array directly.
View Replies
View Related
Dec 8, 2014
The array size is fixed improve it to automatically increase the array size by creating a new larger array and copying the contents of the current array into it .I am using a course class and here is the code for the class
public class Course {
private String courseName;
private int numberOfStudents;
private String[] students = new String[100];
public Course(String courseName)
[Code] ....
As you can see I have the array set to size 100, how do i make so it increments each time the user adds a student.
View Replies
View Related