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){
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.
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.
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?
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?
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?
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.
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?
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:
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.
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)
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.. ?
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)?
**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];
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.
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.