🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16032

Help on drawing on canvas on panel

#16032
From: Aslak Poppe
Date: Thu, 08 Apr 1999 00:00
84 lines
2460 bytes
Good Morning Newsgroup,

Could anybody be kind enough to help me with something thats seems like
a trivial problem?

I have an applet where I have a panel with a gridbaglayout inside a
panel with cardlayout.
In this panel I have a new canvas called canvasTest.
How can I draw on this canvas ?
For example draw a rectangle on canvasTest with drawRect();, or a string
with drawString(); ?

I know how to do the drawing on a regular canvas, but I have problems
when I want to draw to this canvas
wich I have added in a panel.

Here is a short examle of code where I want to draw a rectangle on the
canvas "canvasTest":
(The code is for simplicity, just a part of the full code)


package x2000core2;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;


public class x2000 extends Applet {
  boolean isStandalone = false;

  CardLayout cardLayout1 = new CardLayout();
  Panel panelcard1 = new Panel();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  GridBagConstraints gbc1 = new GridBagConstraints();

  Canvas canvasTest = new Canvas();


  //Construct the applet

  public x2000() {
  }
//Initialize the applet

  public void init() {
    try {
    jbInit();
    }
    catch (Exception e) {
    e.printStackTrace();
    }
  }

//Component initialization

  private void jbInit() throws Exception {
    this.setLayout(borderLayout1);
    this.setSize(500,400);
    panel2.setLayout(cardLayout1);
    panelcard1.setLayout(gridBagLayout1);
    canvasTest.setSize(150,150);
    canvasTest.setBackground(new Color(0, 0, 192));

    gbc1.gridx=24;
    gbc1.gridy=7;
    gbc1.gridwidth=17;
    gbc1.gridheight=17;
    gbc1.anchor=GridBagConstraints.WEST;
    gridBagLayout1.setConstraints(canvasTest,gbc1);
    panelcard1.add(canvasTest);

  }

}

Best regard

Aslak Poppe
aslak.poppe@radsoft.no

--
e-post: aslak.poppe@radsoft.no
Internett: http://www.radsoft.no
Technical Details
Message-ID: <370C923D.9F00C656@radsoft.no>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,80ac0cd4ac7cb666,start
X-Google-Attributes: gidf74b3,public
From: Aslak Poppe <aslak.poppe@radsoft.no>
Subject: Help on drawing on canvas on panel
Date: 1999/04/08
Message-ID: <370C923D.9F00C656@radsoft.no>
X-Deja-AN: 463996814
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: RADsoft AS
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language