Ignore this please.it's not a real post.will be deleted soon.  

Posted by: Shreyasi Ghosh

// Exercise 11.6 Solution// Concentric.java// This program draws concentric circles

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;
public class Concentric extends JFrame {
public Concentric()

{

super( "Concentric" );

setSize( 300, 300 );

show();

}
public void paint( Graphics g ) {

for ( int x = 0; x <= 160; x += 10 ) {

int y = 160 - ( x * 2 );

g.drawOval( x + 30, x + 30, y, y );

}

}
public static void main( String args[] )

{ Concentric app = new Concentric();

app.addWindowListener(

new WindowAdapter() {

public void windowClosing( WindowEvent e ) {

System.exit( 0 ); }

}

);

}

}
---------------------------------------------------------------------------------------
11.12
// Exercise 11.12 Solution// Lines1.java// This program draws lines of random sizes and colors

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;
public class Lines1 extends JFrame {
public Lines1() { super( "Drawing Lines" ); setSize( 200, 200 ); show(); }
public void paint( Graphics g ) { for ( int y = 10; y < 200; y += 10 ) { int x1 = ( int ) ( 1 + Math.random() * 199 ); g.setColor( new Color( ( float ) Math.random(), ( float ) Math.random(), ( float ) Math.random() ) ); g.drawLine( 1, y, x1, y ); } } public static void main( String args[] ) { Lines1 app = new Lines1(); app.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); }
}

---------------------------------------------------------------------------------------------------------
11.15
// Exercise 11.15 Solution// Draw.java// This program randomly draws characters// Note: cover, resize, or restart the program// repeatedly to see multiple characters drawnimport javax.swing.*;import java.awt.*;import java.awt.event.*;
public class Draw extends JFrame { private final int DELAY = 3000000;
public Draw() { super( "Drawing Characters" ); setSize( 200, 200 ); show(); }
public void paint( Graphics g ) { int fontSize = ( int ) ( 10 + Math.random() * 63 ); int x = ( int ) ( 30 + Math.random() * 341 ); int y = ( int ) ( 50 + Math.random() * 95 ); char letters[] = { 'V', 'O', 'L', 'S', '8', '7' }; Font f = new Font( "Monospaced", Font.BOLD, fontSize );
g.setColor( new Color( ( float ) Math.random(), ( float ) Math.random(), ( float ) Math.random() ) ); g.setFont( f ); g.drawChars( letters, ( int ) ( Math.random() * 6 ), 1, x, y );
for ( int h = 1; h < DELAY; h++ ) ; // slow things down repaint(); }
public static void main( String args[] ) { Draw app = new Draw(); app.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); }}

-------------------------------------------------------------------------------------------------------------
11.16
// Exercise 11.16 Solution// Grid.java// This program draws an 8 x 8 gridimport javax.swing.*;import java.awt.*;import java.awt.event.*;
public class Grid extends JFrame { public Grid() { super( "Grid" ); setSize( 200, 200 ); show(); } public void paint( Graphics g ) { int y = 30, x1 = 30;
for ( int r = 1; r <= 8; r++, y += 10 ) g.drawLine( 30, y, 100, y );
for ( int c = 1; c <= 8; c++, x1 += 10 ) g.drawLine( x1, 30, x1, 100 ); }
public static void main( String args[] ) { Grid app = new Grid(); app.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); }}

---------------------------------------------------------------------------------------------------------------
11.20
// Exercise 11.20 Solution// Pyramid.java// This program draws a tetrahedronimport javax.swing.*;import java.awt.*;import java.awt.geom.*;import java.awt.event.*;
public class Pyramid extends JFrame {
public Pyramid() { super( "Pyramid" ); setSize( 275, 150 ); show(); }
public void paint( Graphics g ) { int basex[] = { 100, 200, 150, 50, 100 }; int basey[] = { 100, 100, 130, 130, 100 }; int x = 110, y = 40;
Graphics2D g2d = ( Graphics2D ) g;
GeneralPath tetra = new GeneralPath();
g2d.setColor( Color.red ); tetra.moveTo( basex[ 0 ], basey[ 0 ] );
for ( int i = 1; i < 5; i++ ) { tetra.lineTo( x, y ); tetra.moveTo( basex[ i - 1 ], basey[ i - 1 ] ); tetra.lineTo( basex[ i ], basey[ i ] ); }
tetra.closePath(); g2d.draw( tetra ); }
public static void main( String args[] ) { Pyramid app = new Pyramid(); app.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); }}

----------------------------------------------------------------------------------------------------------
11.29
// Exercise 11.29 Solution// RollDie.java// Roll a six-sided die 6000 timesimport javax.swing.*;import java.util.Random;import java.awt.event.*;import java.awt.*;
public class RollDie extends JFrame {
public RollDie() { super( "Roll Die" ); setSize( 275, 150 ); show(); }
public void paint( Graphics g ) { int yPosition = 50, face; int frequency[] = new int[ 7 ]; Random r = new Random();
for ( int roll = 1 ; roll <= 6000; roll++ ) { face = 1 + Math.abs( r.nextInt() % 6 ); ++frequency[ face ]; } g.setColor( Color.white ); g.fillRect( 0, 0, 275, 150 ); // 275 x 150 g.setColor( Color.black ); g.drawString( "Face", 25, yPosition ); g.drawString( "Frequency", 100, yPosition );
for ( int i = 1; i < frequency.length; i++ ) { yPosition += 15; g.drawString( String.valueOf( i ), 25, yPosition ); g.drawString( String.valueOf( frequency[ i ] ), 100, yPosition ); } }
public static void main( String args[] ) { RollDie app = new RollDie(); app.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); }}

This entry was posted on 6:06 PM . You can leave a response and follow any responses to this entry through the Subscribe to: Post Comments (Atom) .

1 high fives

I like your blog.
Carlos
Portugal

Post a Comment