This site requires JavaScript, please enable it in your browser!
Greenfoot back
Kartoffelbrot
Kartoffelbrot wrote ...

2013/7/28

drawImage with ImageIcon

Kartoffelbrot Kartoffelbrot

2013/7/28

#
I want to programm chess, but without Greenfoot. I make that with blueJ and "Java-Editor". Therefore I need to paint the images of the fields. But I don't want to paint an image for every possible comination (white king ond white field - white king on black field - black king on white field - black king on black field... -> 6*4=24 images). I want to paint the images if the figures onto an ImageIcon, which has an black image of 50px X 50px or a white image with the same dimensions (a field). So I need a method like the drawImage method in GreenfootImage only for class ImageIcon. Any suggestions?
danpost danpost

2013/7/28

#
In my 'Chess: Drag-n-Drop' scenario, I did not use any actual images for the pieces. I used (char)9812 through (char)9823 as text for the piece images. Maybe you can do something with them, since they can be used in String objects (as opposed to image objects).
Kartoffelbrot Kartoffelbrot

2013/7/28

#
I downloaded it to know more about it. It's interesting to see, that such Characters exist.
Kartoffelbrot Kartoffelbrot

2013/7/28

#
Then I can use the setText method of my JButtons. Thank you.
Gevater_Tod4711 Gevater_Tod4711

2013/7/28

#
A little suggestion for improvement: wouldn't JLabels be better for the fields on the chessbord? I think that would make it look more like a chessboard. A JLabel can also reakt on mouse events like a JButton. When it's clicked by the mouse it would have the same reaction. For example you could use some code like this for the labels:
JLabel label = new JLabel("Some text or Symbols");
label.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent arg0) {
        //this method will be executed when you click on the field.
        //almost like buttons.
        System.out.println("mouseEvent");
    }
});
Kartoffelbrot Kartoffelbrot

2013/7/28

#
Thanky, but because I painted an own image, which is only black they don't look like buttons any more. I didn't know that JLabels can be used as buttons, too, but I don't want to change it all, because all 64 fields (I have made a class "Feld" for them) are JButtons and in the GUI class they aren't saved in an array or a list like I wanted that first. I've enumerated them like: JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JButton jButton3 = new JButton(); That's very ugly, but I don't have much experience with that. My try to use an Array and to save them with a for-loop wasn't lucky because the actionListener didn't like it and I wasn't able to fix that. I hope you understand now.
You need to login to post a reply.