So I have a custom JLabel, and I want to paint a circle around it. The JLabel paints fine, but the custom circle code does not.
I figured I could do it all in one class, instead having another class that draws the circle separately, I'm not sure if I can do this or not.
Once again, the Jlabel with an indicated icon shows properly, but the custom circle code does not.
TowerMarker.java
My Main class, just a snippet to give an idea.Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package maputilproject;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author WESNC
*/
public final class TowerMarker extends JLabel
{
private int x, y, id;
private ImageIcon ic;
private String ql;
public TowerMarker(int id, int x, int y, ImageIcon ic, String ql)
{
this.x = x;
this.y = y;
this.ic = ic;
this.ql = ql;
setBounds(x, y, 40, 85);
setIcon(ic);
setToolTipText("QL: "+ql);
}
@Override
public int getX()
{
return x;
}
@Override
public int getY()
{
return y;
}
public String getQL()
{
return ql;
}
public ImageIcon getImageIcon()
{
return ic;
}
public int getID()
{
return id;
}
@Override
public String toString()
{
return x+":"+y+":"+ql;
}
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawOval(x, y, 100, 100);
}
}
Any help upon this matter?Code:towers_mr.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
//JLabel mrTower = new JLabel(new ImageIcon(getClass().getResource("/tower_mr.png")));
//map.add(mrTower);
//mrTower.setBounds(mX, mY, 40, 85);
final int mXStore = mX-15;
final int mYStore = mY-42;
Object[] test = {"Input Tower QL", "Example: 10, 20, 30, 40, etc"};
String s = (String)JOptionPane.showInputDialog(pmenu, test);
Random r = new Random();
TowerMarker mrt = new TowerMarker(r.nextInt(10000), mXStore, mYStore, new ImageIcon(getClass().getResource("/tower_v2_mr.png")), s);
map.add(mrt);
map.repaint();
mrt.addMouseListener(new MouseAdapter()
{
@Override
public void mouseReleased(MouseEvent evt)
{
if(evt.isPopupTrigger())
{
mX = evt.getX();
mY = evt.getY();
rclick.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
}
);
}
}
);
EDIT: Also, the map is just a jlabel WHICH may be some of my problem, but if so why does everything else work fine?

