Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Draw Flag in Java

Wed May 06, 2009 3:24 am

Draw your country Flag in Java
This is the flag class :
Code:

import javax
.swing.*;
import java.awt.*;
/**
 
  Flag Description:
two equal vertical bands of green (hoist side) and white;
a red, five-pointed star within a red crescent centered
over the two-color boundary; the crescent, star,
and color green are traditional symbols.
 */

public class AlgerianFlag extends JComponent{
    public void paint( Graphics g )
    {

        Graphics2D g2 = ( Graphics2D ) g;
        
// draw the green space
        g2.setColor(Color.blue); 
        g2
.fillRect(0, 0, 600, 600);
// draw the green space
        g2.setColor(Color.GREEN); 
        g2
.fillRect(50, 50, 150, 200);
        
// draw the white space
        g2.setColor(Color.WHITE); 
        g2
.fillRect(200, 50, 150, 200);
        
        
    
}
}


and this is the test class:

import javax.swing.*;
import java.awt.*;

public class AlgerianFlagTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // draw the red star
    
//create new frame object 
        JFrame frame = new JFrame ("Algeria");        
// set the size of the frame
        frame.setSize(600 ,600);
// set the location of the frame
        frame.setLocation(100,100);
// create new object of type flag
        AlgerianFlag flag = new AlgerianFlag();
// add the object flag to the frame
        frame.add(flag);
//display the frame and close the program when close is pushed
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    
    
}
            }

 




Post a reply
  Related Posts  to : Draw Flag in Java
 Get table column flag in php     -  
 Draw An Arc in java     -  
 draw Oval in java     -  
 draw Calendar in java     -  
 draw text effects in java     -  
 Draw Dashed Oval in java     -  
 Changing the color of a graph draw in java     -  
 Java code to draw shortest path tree     -  
 draw cube 3d java-Cube 3D     -  
 How to draw a gun     -  

Topic Tags

Java Graphics