Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1841
| From | "sydpolen" <sydpolen@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Graphics drawing prob |
| Message-ID | <1181857297.350745.6380@i13g2000prf.googlegroups.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <53fci.76017$3L1.35950@newsfe14.lga> |
| Date | 2011-04-27 15:35 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
On 14 Jun., 19:39, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> sydpo...@gmail.com wrote:
> > Hi,
>
> > I'm a java gui newbie. I have this problem;
>
> > I made a class "Gui" I want to use as a template for future Gui
> > builds. I want to draw lines in the center. I made a "test" method
> > which I call from main class. For some reason the line I attempt to
> > draw is not visible. When I call sleep between the initiate() and the
> > test() methods the line will sometimes be visible.
>
> > I would appreciate any pointers of what I'm doing wrong. I paste the
> > source ...
>
> Drawing needs to be done in the paintComponent() method for Swing
> components.
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> public class XComponent extends JComponent {
> public XComponent() {
> setPreferredSize(new Dimension(40,40));
> }
>
> public void paintComponent(Graphics g) {
> g.drawLine(0,0,getWidth(),getHeight());
> g.drawLine(getWidth(),0,0,getHeight());
> }
>
> public static void main(String[] args) {
> Runnable r = new Runnable() {
> public void run() {
> JFrame f = new JFrame();
> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> XComponent x = new XComponent();
> f.add(x);
> f.pack();
> f.setVisible(true);
> }
> };
> EventQueue.invokeLater(r);
> }
>
> }
>
> --
>
> Knute Johnson
> email s/nospam/knute/
Ok, thx a lot Knute, with your advice I made it work.
Can someone recommend a link where I can find something about how the
graphical elements of Java works explained in a short and precise way
(both high level and low level topics). Since I'm a newbie with regard
to graphics, I also seek information about the basics, e.g. when I
read some stuff mentioning the word "render", I would like to know
what actually happens on the underlying levels when graphics are
rendered.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Graphics drawing problem "sydpolen" <sydpolen@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
Re: Graphics drawing prob "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
Re: Graphics drawing prob "sydpolen" <sydpolen@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
Re: Graphics drawing prob "Judy Szikora" <judy.szikora@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
Re: Graphics drawing prob "Jul" <jul@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
csiph-web