Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1834 > unrolled thread
| Started by | "sydpolen" <sydpolen@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:35 +0000 |
| Last post | 2011-04-27 15:35 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.java.gui
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
| From | "sydpolen" <sydpolen@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:35 +0000 |
| Subject | Graphics drawing problem |
| Message-ID | <1181840486.636009.196880@q19g2000prn.googlegroups.com> |
To: comp.lang.java.gui
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 ...
import java.awt.*;
import javax.swing.*;
public class StartGui {
public static void main(String[] args) throws Exception{
Gui gui = new Gui();
gui.initiate();
//Thread.sleep(2000);
gui.test(100,100,300,300);
}
}
import javax.swing.*;
import java.awt.*;
public class Gui extends JFrame{
Color cN = Color.LIGHT_GRAY;
Color cW = Color.LIGHT_GRAY;
Color cC = Color.LIGHT_GRAY;
Color cE = Color.LIGHT_GRAY;
Color cS = Color.LIGHT_GRAY;
Color cGap = Color.BLACK;
int widthW = 200;
int widthC = 400;
int widthE = 200;
int heightN = 150;
int heightC = 400;
int heightS = 150;
Graphics graphics;
JPanel n;
JPanel s;
JPanel e;
JPanel w;
JPanel c;
public Gui() {
new JFrame("Gui");
n = new JPanel();
w = new JPanel();
e = new JPanel();
s = new JPanel();
c = new JPanel();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public void initiate() {
getContentPane().setLayout(new BorderLayout(2,2));
getContentPane().setBackground(cGap);
n.setBackground(cN);
n.setPreferredSize(new Dimension(widthE+widthC+widthW,heightN));
w.setBackground(cW);
w.setPreferredSize(new Dimension(widthW,heightC));
c.setBackground(cC);
c.setPreferredSize(new Dimension(widthC,heightC));
e.setBackground(cE);
e.setPreferredSize(new Dimension(widthE,heightC));
s.setBackground(cS);
s.setPreferredSize(new Dimension(widthE+widthC+widthW,heightS));
getContentPane().add(e,BorderLayout.EAST);
getContentPane().add(w,BorderLayout.WEST);
getContentPane().add(n,BorderLayout.NORTH);
getContentPane().add(s,BorderLayout.SOUTH);
getContentPane().add(c,BorderLayout.CENTER);
pack();
}
public void test(int x1, int y1, int x2, int y2){
c.setBackground(Color.BLACK);
graphics = c.getGraphics();
graphics.setColor(Color.GREEN);
graphics.drawLine(x1,y1,x2,x2);
}
}
---
* 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
[toc] | [next] | [standalone]
| From | "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:35 +0000 |
| Subject | Re: Graphics drawing prob |
| Message-ID | <53fci.76017$3L1.35950@newsfe14.lga> |
| In reply to | #1834 |
To: comp.lang.java.gui
sydpolen@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/
---
* 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
[toc] | [prev] | [next] | [standalone]
| From | "sydpolen" <sydpolen@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:35 +0000 |
| Subject | Re: Graphics drawing prob |
| Message-ID | <1181857297.350745.6380@i13g2000prf.googlegroups.com> |
| In reply to | #1836 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Judy Szikora" <judy.szikora@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:35 +0000 |
| Subject | Re: Graphics drawing prob |
| Message-ID | <0rxci.29220$NV3.24765@pd7urf2no> |
| In reply to | #1841 |
To: comp.lang.java.gui sydpolen@gmail.com wrote: ... > > 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. > The API doc for java.awt.Graphics and java.awt.Graphics2D has important information but may be too concise. The docs/index.html page in your JDK installation has a link to Java2D and Imaging with pointers to more doc, including the Java tutorial. Google and a good bookseller are worth a look too. -- Judy Szikora, Apprisant Technologies Inc. http://www.apprisant.com --- * 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
[toc] | [prev] | [next] | [standalone]
| From | "Jul" <jul@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:35 +0000 |
| Subject | Re: Graphics drawing prob |
| Message-ID | <1181930154.256395.236560@o61g2000hsh.googlegroups.com> |
| In reply to | #1846 |
To: comp.lang.java.gui > The API doc for java.awt.Graphics and java.awt.Graphics2D has important > information but may be too concise. The docs/index.html page in your JDK > installation has a link to Java2D and Imaging with pointers to more doc, > including the Java tutorial. Google and a good bookseller are worth a > look too. Thanks Judy, I already looked at these docs, good material, but I was hoping someone would have a link to an outstanding site about the topics in question, which might not pop-up at the first 1-5 Google search pages. Cheers, Jul --- * 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web