🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #7718

graphic primitive in JPanel

#7718
From: Frauke Voss
Date: Thu, 04 Jan 2001 21:34
54 lines
2524 bytes
Hi everybody,

I'm trying to put a custom graphic into a JPanel, so that it is a component
of the Panel and gets painted after the Panel.

The JPanel is the field for a game and the custom graphic is a gaming piece.

public class SchiffeversenkenApplet extends JApplet
{
    public void init()
    {
        // this test is working properly:
        JButton testbutton = new JButton("Hallo");
        // localPlayer.getField() returns the game-field
        // add button to game-field
        localPlayer.getField().add(testbutton);

        // this is not working:
        // create gamingpiece
        Gamingpiece schiffsteil = new Gamingpiece(localPlayer.getField());
        localPlayer.getField().add(schiffsteil);

        // add game-field to contentPane
        Container contentPane = getContentPane();
        contentPane.add(localPlayer.getField());
    }
}

// tried to extend Gamingpiece from JPanel and JLabel as mentioned in
java.sun.com tutorial
class Gamingpiece extends JLabel
{
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.setColor(Color.black);
        g.fillOval(100, 100, 20, 20);
    }

    // also tried this instead of adding the gamingpiece from the main
method:
    public Schiffsteil2(Gamingpiece spielfeld)
    {
        spielfeld.add(this);
    }
..
}


I just can't get the gaming-piece to be painted, I'd be greatful for any
hints or advices.

Cheers,
Frauke
Technical Details
Message-ID: <978644095.156400@DS9.ai-lab.fh-furtwangen.de>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.algonet.se!algonet!news-sto.telia.net!News.Amsterdam.UnisourceCS!newsfeed-zh.ip-plus.net!news.ip-plus.net!news.tesion.net!news.belwue.de!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,e0bb444c27d40c87,start
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2001-01-04 13:35:09 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.algonet.se!algonet!news-sto.telia.net!News.Amsterdam.UnisourceCS!newsfeed-zh.ip-plus.net!news.ip-plus.net!news.tesion.net!news.belwue.de!not-for-mail
From: "Frauke Voss" <voss@dpi72.de>
Newsgroups: borland.public.jbuilder.java.swing
Subject: graphic primitive in JPanel
Date: Thu, 4 Jan 2001 22:34:01 +0100
Organization: Fachhochschule Furtwangen
Lines: 57
Message-ID: <978644095.156400@DS9.ai-lab.fh-furtwangen.de>
NNTP-Posting-Host: ds9.ai-lab.fh-furtwangen.de
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
Cache-Post-Path: DS9.ai-lab.fh-furtwangen.de!unknown@buckmulligan.ghb.fh-furtwangen.de
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)