Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26862
| Date | 2013-12-12 19:07 +0000 |
|---|---|
| From | lipska the kat <"lipskathekat at yahoo dot co dot uk"> |
| Organization | Trollbusters 3 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Basic 2d graphics in Java |
| References | <527c86f0-1b3d-4103-bd42-a5dcd9ade567@googlegroups.com> <plotting-20131212192143@ram.dialup.fu-berlin.de> |
| Message-ID | <LbGdnfwd5ML6lDfPnZ2dnUVZ8ludnZ2d@bt.com> (permalink) |
On 12/12/13 18:42, Stefan Ram wrote:
> tomcees_pc@yahoo.com writes:
>> Can anyone share some simple java code to:
>> 1. Set up a small (say 320w x 240h) 2d window.
>> 2. Set(color) and Read (color) of pixels within this window.
>
> class Main extends javax.swing.JComponent implements java.lang.Runnable
> { final int X = 320; final int Y = 200;
> private static final long serialVersionUID = 0L;
> final java.awt.image.BufferedImage window
> = new java.awt.image.BufferedImage
> ( X, Y, java.awt.image.BufferedImage.TYPE_INT_RGB );
> public int readColor( final int x, final int y )
> { return Main.this.window.getRGB( x, y ); }
> public void setColor( final int x, final int y, final int color )
> { Main.this.window.setRGB( x, y, color ); }
> public static void main( final java.lang.String args[] )
> { java.awt.EventQueue.invokeLater( new Main() ); }
> @java.lang.Override public final void run()
> { final javax.swing.JFrame frame = new javax.swing.JFrame( "Main" );
> Main.this.setPreferredSize( new java.awt.Dimension( 320, 200 ));
> Main.this.setColor( X/2, Y/2, 0xFFFFFF );
> java.lang.System.out.println( Main.this.readColor( X/2, Y/2 ));
> frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE );
> frame.add( Main.this ); frame.pack(); frame.setVisible( true ); }
> @java.lang.Override
> public void paintComponent( final java.awt.Graphics graphics )
> { graphics.drawImage( Main.this.window, 0, 0, null ); }}
Jeez
If anyone had written code formatted like that when I was working I'd
have sacked the bugger.
--
Lipska the Kat©: Troll hunter, sandbox destroyer,
treacherous feline and farscape dreamer of Aeryn Sun
GNU/Linux user #560883 - http://www.linuxcounter.net
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Basic 2d graphics in Java tomcees_pc@yahoo.com - 2013-12-12 08:45 -0800
Re: Basic 2d graphics in Java markspace <markspace@nospam.nospam> - 2013-12-12 09:39 -0800
Re: Basic 2d graphics in Java lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-12-12 19:07 +0000
Re: Basic 2d graphics in Java Joerg Meier <joergmmeier@arcor.de> - 2013-12-12 20:43 +0100
Re: Basic 2d graphics in Java lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-12-12 19:47 +0000
Re: Basic 2d graphics in Java lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-12-12 20:14 +0000
Re: Basic 2d graphics in Java tomcees_pc@yahoo.com - 2013-12-12 12:37 -0800
Re: Basic 2d graphics in Java Jeff Higgins <jeff@invalid.invalid> - 2013-12-12 17:42 -0500
csiph-web