Java Swing – Draw Station Names using GPS Coordinates on JPanel

I am working on an assignment and got stuck at a certain point. I am given a .txt file with a series of stations, and I am supposed to draw the station names using the GPS coordinates given to me, but I can’t translate those coordinates to XY coordinates that a JPanel uses. Also, GPS … Continue reading “Java Swing – Draw Station Names using GPS Coordinates on JPanel”

How to use addMouseListener on the elements of an array of JPanels without adding it to each single element.?

I am trying to make a chess program where I have an 8×8 array of JPanels which all require an addMouseListener but in this addMouseListener I need to make use of the index of that array for it to work, like this: panels[0][0].addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { panels[0][0].setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)); } public void mouseReleased(MouseEvent … Continue reading “How to use addMouseListener on the elements of an array of JPanels without adding it to each single element.?”

How can I make it so when I press a JButton it checks whether you entered something in JTextFeild is right or wrong? (Just like a lock in Java)

Sorry if this question has already been answered somewhere or if I don’t make sense, but I was wondering if I can create a ‘lock’ on a JPanel. So far I have made it so when I press the button it clears everything and a JLabel appears. However, I can’t make it so when I … Continue reading “How can I make it so when I press a JButton it checks whether you entered something in JTextFeild is right or wrong? (Just like a lock in Java)”

Trouble putting my Java FreeChart into the JPanel

I have the following code: However i cant seem to put my output into the JPanel i have created, i have experimented but i can either create the chart and make it appear in a separate chart frame window or it doesnt appear at all, , can someone assist? package javaapplication1; import java.awt.Color; import java.awt.Container; … Continue reading “Trouble putting my Java FreeChart into the JPanel”

ACM Graphics, Moving an image across the screen

I can’t get my code to compile. I’m Trying to get an Image to move across the screen by using a timer. Can I get some help? It there is a background gif that i have working, and a png of an turtle is supposed to move across the screen but I can’t get it … Continue reading “ACM Graphics, Moving an image across the screen”

Modifying a jPanel using buttons on another jPanel

I’ve just approached Java and I’m working on a project for my University class. I’m working on a Milionaire game but I’m stuck. I’ve got a JFrame class in which I have 2 panels. The first one is made of buttons, the second one is the panel I want to change by pressing the buttons. … Continue reading “Modifying a jPanel using buttons on another jPanel”

Why my image does not save

I have a simple program with JFrame and Jpanel on it and I want to draw a line on the JPanel and save the result of the drawing to an image. But it completely does not work. Where was I wrong? import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.logging.Level; … Continue reading “Why my image does not save”

JPanel sizing inside Another JPanel

I really need help with this. I have been having problems resizing the gameBoardPanel JPanel that is added the the main Panel. Everything I have tried including resizing it has not helped, I basically want to add the gameBoardPanel at 400×400 to the main panel (which is 400×500), leaving me 400×100 of space for other … Continue reading “JPanel sizing inside Another JPanel”

Replace current image in JPanel with another one

I´m writing a program where images are displayed on a JPanel, but I´m having trouble replacing the existing image when I open a new one. Is there a easy way to remove the old image from the ImageIcon and replace with the new one? I thought that something like mp.remove(pic); would work here, but it … Continue reading “Replace current image in JPanel with another one”