Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26857 > unrolled thread
| Started by | tomcees_pc@yahoo.com |
|---|---|
| First post | 2013-12-12 08:45 -0800 |
| Last post | 2013-12-12 17:42 -0500 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | tomcees_pc@yahoo.com |
|---|---|
| Date | 2013-12-12 08:45 -0800 |
| Subject | Basic 2d graphics in Java |
| Message-ID | <527c86f0-1b3d-4103-bd42-a5dcd9ade567@googlegroups.com> |
Hello: I'm working through re-learning java and would like to solicit some help. 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. TIA for your help, TomC
[toc] | [next] | [standalone]
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Date | 2013-12-12 09:39 -0800 |
| Message-ID | <l8csca$ibn$1@dont-email.me> |
| In reply to | #26857 |
On 12/12/2013 8:45 AM, tomcees_pc@yahoo.com wrote: > Hello: > > I'm working through re-learning java and would like to solicit some help. > > 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. <http://docs.oracle.com/javase/tutorial/2d/>
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"lipskathekat at yahoo dot co dot uk"> |
|---|---|
| Date | 2013-12-12 19:07 +0000 |
| Message-ID | <LbGdnfwd5ML6lDfPnZ2dnUVZ8ludnZ2d@bt.com> |
| In reply to | #26857 |
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
[toc] | [prev] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2013-12-12 20:43 +0100 |
| Message-ID | <1c4r3x4q3rnmm.g3jsymfn2v9q.dlg@40tude.net> |
| In reply to | #26862 |
On Thu, 12 Dec 2013 19:07:17 +0000, lipska the kat wrote: > If anyone had written code formatted like that when I was working I'd > have sacked the bugger. I was thinking the same reading about Stefan teaching students his ridiculously eccentric code style. I wonder if they (or he) realizes that if they are ever asked to provide a code sample before or during an interview, they'll be unceremoniously asked to leave. Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"lipskathekat at yahoo dot co dot uk"> |
|---|---|
| Date | 2013-12-12 19:47 +0000 |
| Message-ID | <dvmdnT4iZbFSjzfPnZ2dnUVZ8jCdnZ2d@bt.com> |
| In reply to | #26864 |
On 12/12/13 19:43, Joerg Meier wrote: > On Thu, 12 Dec 2013 19:07:17 +0000, lipska the kat wrote: > >> If anyone had written code formatted like that when I was working I'd >> have sacked the bugger. > > I was thinking the same reading about Stefan teaching students his > ridiculously eccentric code style. I wonder if they (or he) realizes that > if they are ever asked to provide a code sample before or during an > interview, they'll be unceremoniously asked to leave. I can't believe that he actually teaches people to write code like that! Does he? surely not. It's just his 'c.l.j.p style' I'm sure. -- Lipska the Kat©: Troll hunter, sandbox destroyer, treacherous feline and farscape dreamer of Aeryn Sun GNU/Linux user #560883 - http://www.linuxcounter.net
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"lipskathekat at yahoo dot co dot uk"> |
|---|---|
| Date | 2013-12-12 20:14 +0000 |
| Message-ID | <g-2dncdh0_alhDfPnZ2dnUVZ8jadnZ2d@bt.com> |
| In reply to | #26857 |
On 12/12/13 16:45, tomcees_pc@yahoo.com wrote:
> Hello:
>
> I'm working through re-learning java and would like to solicit some help.
>
> 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.
>
> TIA for your help,
> TomC
Try this
With suitable acknowledgments to Stefan Ram of this parish.
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import javax.swing.JFrame;
class Main extends JComponent implements Runnable {
int X = 320;
int Y = 200;
private static final long serialVersionUID = 0L;
BufferedImage window = new BufferedImage( X, Y,
BufferedImage.TYPE_INT_RGB );
public int readColor(int x, int y ){
return window.getRGB( x, y );
}
public void setColor( int x, int y, int color ){
window.setRGB( x, y, color );
}
public static void main(String args[] ){
EventQueue.invokeLater(new Main() );
}
@Override
public void run(){
JFrame frame = new JFrame( "Main" );
setPreferredSize( new Dimension( X, Y ));
setColor( X/2, Y/2, 0xFFFFFF );
System.out.println(readColor( X/2, Y/2 ));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
frame.add(this);
frame.pack();
frame.setVisible( true );
}
@Override
public void paintComponent(Graphics graphics ){
graphics.drawImage(window, 0, 0, null );
}
}
--
Lipska the Kat©: Troll hunter, sandbox destroyer,
treacherous feline and farscape dreamer of Aeryn Sun
GNU/Linux user #560883 - http://www.linuxcounter.net
--
Lipska the Kat©: Troll hunter, sandbox destroyer,
treacherous feline and farscape dreamer of Aeryn Sun
GNU/Linux user #560883 - http://www.linuxcounter.net
[toc] | [prev] | [next] | [standalone]
| From | tomcees_pc@yahoo.com |
|---|---|
| Date | 2013-12-12 12:37 -0800 |
| Message-ID | <3a150ad5-f334-44f8-8cd9-759c97feb911@googlegroups.com> |
| In reply to | #26866 |
On Thursday, December 12, 2013 3:14:47 PM UTC-5, lipska the kat wrote:
> On 12/12/13 16:45, tomcees_ .com wrote:
>
> > Hello:
>
> >
>
> > I'm working through re-learning java and would like to solicit some help.
>
> >
>
> > 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.
>
> >
>
> > TIA for your help,
>
> > TomC
>
>
>
> Try this
>
>
>
> With suitable acknowledgments to Stefan Ram of this parish.
>
>
>
> import java.awt.Dimension;
>
> import java.awt.EventQueue;
>
> import java.awt.Graphics;
>
> import java.awt.image.BufferedImage;
>
> import javax.swing.JComponent;
>
> import javax.swing.JFrame;
>
>
>
> class Main extends JComponent implements Runnable {
>
> int X = 320;
>
> int Y = 200;
>
>
>
> private static final long serialVersionUID = 0L;
>
> BufferedImage window = new BufferedImage( X, Y,
>
> BufferedImage.TYPE_INT_RGB );
>
>
>
> public int readColor(int x, int y ){
>
> return window.getRGB( x, y );
>
> }
>
>
>
> public void setColor( int x, int y, int color ){
>
> window.setRGB( x, y, color );
>
> }
>
>
>
> public static void main(String args[] ){
>
> EventQueue.invokeLater(new Main() );
>
> }
>
>
>
> @Override
>
> public void run(){
>
> JFrame frame = new JFrame( "Main" );
>
> setPreferredSize( new Dimension( X, Y ));
>
> setColor( X/2, Y/2, 0xFFFFFF );
>
> System.out.println(readColor( X/2, Y/2 ));
>
> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
>
> frame.add(this);
>
> frame.pack();
>
> frame.setVisible( true );
>
> }
>
>
>
> @Override
>
> public void paintComponent(Graphics graphics ){
>
> graphics.drawImage(window, 0, 0, null );
>
> }
>
> }
>
>
>
>
>
>
>
> --
>
> Lipska the Kat�: Troll hunter, sandbox destroyer,
>
> treacherous feline and farscape dreamer of Aeryn Sun
>
> GNU/Linux user #560883 - http://www.linuxcounter.net
>
>
>
>
>
> --
>
> Lipska the Kat�: Troll hunter, sandbox destroyer,
>
> treacherous feline and farscape dreamer of Aeryn Sun
>
> GNU/Linux user #560883 - http://www.linuxcounter.net
Works nicely! Thanks to both of you for the courteous, helpful response!
Regards,
TomC
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2013-12-12 17:42 -0500 |
| Message-ID | <l8de66$2ei$1@dont-email.me> |
| In reply to | #26857 |
On 12/12/2013 11:45 AM, tomcees_pc@yahoo.com wrote:
> Hello:
>
> I'm working through re-learning java and would like to solicit some help.
>
> 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.
>
> TIA for your help,
> TomC
>
Just cause so many are heaping on Swing lately.
package pixel.test;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class PixelTest extends Application {
WritableImage image = new WritableImage(320,240);
PixelReader pixelReader = image.getPixelReader();
PixelWriter pixelWriter = image.getPixelWriter();
//setPixel and readPixel left as an exercise
@Override
public void start(Stage primaryStage) {
ImageView imageView = new ImageView();
imageView.setImage(image);
StackPane root = new StackPane();
root.getChildren().add(imageView);
Scene scene = new Scene(root, 320, 240);
primaryStage.setTitle("Pixel Test");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web