Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 132,153 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,817 people online right now. Registration is fast and FREE... Join Now!




Simple Screen Saver

 
Reply to this topicStart new topic

Simple Screen Saver, Working on a Logo made from simple Polygons

BlitzBitz
post 5 Oct, 2008 - 03:30 PM
Post #1


New D.I.C Head

*
Joined: 5 Oct, 2008
Posts: 2

I've been working at this for a few hours now and I can't get it to run properly.
My goals are to:
have it run full-screen (but that's optional, and I think I can work it out on my own)
have it produce the poly-logo(as i call it) on random parts of the screen every second or so
have the logo in color (which i havent gotten around to doing just yet, any help or tips on this are apreciated)

Viewer, main class:
CODE

import javax.swing.JFrame;

public class ScreenerViewer
{
   public static void main( String args[] )
   {
      JFrame frame = new JFrame("Mayaguez 2010 ScreenSaver");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      
      Screener screenSaver = new Screener();
      
      frame.add(screenSaver);
      frame.setSize(1000, 500);
      frame.setVisible(true);
   }
}


Panel / draw class:
CODE

import java.awt.Graphics;
import java.util.Random;
import javax.swing.JPanel;
import java.awt.Graphics2D;


public class Screener extends JPanel{

public Random generator = new Random();

   int x0 = generator.nextInt(1000);
   int y0 = generator.nextInt(500);
   int time = (int) System.currentTimeMillis();


   public void Paint (Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        
        while(System.currentTimeMillis()-time < 1000/60)//60 repetitions per second(Screen refresh 60 Hz)
            {
      

        g2.draw(LogoDraw.topM(x0, y0));
        
        g2.draw(LogoDraw.bottomM(x0,y0));
        
        g2.draw(LogoDraw.flame1(x0,y0));
        
        g2.draw(LogoDraw.flame2(x0,y0));
        
        
   }
        repaint();
    }
    
}



Method storage / instruction class:
CODE

import java.awt.geom.GeneralPath;
import java.awt.Shape;
import javax.swing.JComponent;

public class LogoDraw extends JComponent{
    

    public static Shape topM(int x0,int y0){
        //Bigger Top M Point Instructions
       // Drawing instructions
        
        int x0Points[] = {x0+3, x0+31, x0+52, x0+73, x0+100, x0+96, x0+73, x0+52, x0+31, x0+7};
        int y0Points[] = {y0+67, y0+40, y0+60, y0+40, y0+67, y0+70, y0+47, y0+66, y0+47, y0+70};
        GeneralPath polygon = new GeneralPath(GeneralPath.WIND_NON_ZERO, x0Points.length);
        polygon.moveTo(x0Points[0], y0Points[0]);

        for (int index = 1; index < x0Points.length; index++) {
                polygon.lineTo(x0Points[index], y0Points[index]);
        };

        polygon.closePath();
            return polygon;
        }
    
        public static Shape bottomM(int x0,int y0){
            //Smaller Bottom M Point Instructions

               // Drawing instructions
            
            int x0Points[] = {x0+10, x0+31, x0+52, x0+73, x0+93, x0+90, x0+62, x0+52, x0+31, x0+13};
            int y0Points[] = {y0+73, y0+55, y0+73, y0+55, y0+73, y0+76, y0+73, y0+77, y0+73, y0+76};
            GeneralPath polygon = new GeneralPath(GeneralPath.WIND_NON_ZERO, x0Points.length);
            polygon.moveTo(x0Points[0], y0Points[0]);

            for (int index = 1; index < x0Points.length; index++) {
                    polygon.lineTo(x0Points[index], y0Points[index]);
            };

            polygon.closePath();
            
            return polygon;
        }
        public static Shape flame1(int x0,int y0){
            //First Triangle
               // Drawing instructions
            
            int x0Points[] = {x0+51, x0+40, x0+51};
            int y0Points[] = {y0+51, y0+37, y0+24};
            GeneralPath polygon = new GeneralPath(GeneralPath.WIND_NON_ZERO, x0Points.length);
            polygon.moveTo(x0Points[0], y0Points[0]);

            for (int index = 1; index < x0Points.length; index++) {
                    polygon.lineTo(x0Points[index], y0Points[index]);
            };

            polygon.closePath();
            
            return polygon;

        }
        public static Shape flame2(int x0, int y0){
            //Second Triangle
            
       // Drawing instructions
            
            int x0Points[] = {x0+51, x0+62, x0+51};
            int y0Points[] = {y0+35, y0+19, y0+5};
            GeneralPath polygon = new GeneralPath(GeneralPath.WIND_NON_ZERO, x0Points.length);
            polygon.moveTo(x0Points[0], y0Points[0]);

            for (int index = 1; index < x0Points.length; index++) {
                    polygon.lineTo(x0Points[index], y0Points[index]);
            };

            polygon.closePath();
            
            return polygon;
        }
}





So far It opens an empty frame and panel, but does nothing else.

So, any help/tips on having it run properly are very much apreciated.
User is offlineProfile CardPM

Go to the top of the page

stauffski
post 5 Oct, 2008 - 04:19 PM
Post #2


D.I.C Head

**
Joined: 3 Nov, 2007
Posts: 137



Thanked 16 times
My Contributions


I'm still looking at your code, but I figure I'd let you know what I see right now so you can get started. Currently I have three things that I would like to point out to you.

1.) You never call your Paint method from the class Screener.
2.) In the method Paint from the class Screener, you never enter the loop.
3.) In the method Paint from the class Screener, I think you might want to move the repaint() method up into the while loop.

These thoughts are my initial thoughts and may be wrong, but I'm still looking.

Good Luck!
User is offlineProfile CardPM

Go to the top of the page

BlitzBitz
post 5 Oct, 2008 - 05:38 PM
Post #3


New D.I.C Head

*
Joined: 5 Oct, 2008
Posts: 2

Here are some Updates I've made to the code so far
Still there are some very big holes (sigh)

Main Class:
CODE

import javax.swing.JFrame;
import javax.swing.Timer;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ScreenerViewer
{
   public static void main( String args[] )
   {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      
      frame.setTitle("Mayaguez 2010 ScreenSaver");
      Screener screenSaver = new Screener();
      
      frame.add(screenSaver);
      
      frame.setSize(1000, 500);
      
      frame.setVisible(true);
    
      class MyListener implements ActionListener //Timer Listener, for Delayed events
      {
          public void actionPerformed(ActionEvent event)
          {    
              // This action will be executed at each timer
              //What goes here?
          }
      }
          MyListener listener = new MyListener();
          Timer t = new Timer(2000, listener); // Two Second Delay
          t.start();
   }
}

Method And Drawing Instructions:
CODE

import java.awt.geom.GeneralPath;
import java.awt.Shape;
import javax.swing.JComponent;

public class LogoDraw extends JComponent{
    

    public static Shape topM(int x0,int y0){
        //Bigger Top M Point Instructions
       // Drawing instructions
        
        int x0Points[] = {x0+3, x0+31, x0+52, x0+73, x0+100, x0+96, x0+73, x0+52, x0+31, x0+7};
        int y0Points[] = {y0+67, y0+40, y0+60, y0+40, y0+67, y0+70, y0+47, y0+66, y0+47, y0+70};
        GeneralPath polygon = new GeneralPath(GeneralPath.WIND_NON_ZERO, x0Points.length);
        polygon.moveTo(x0Points[0], y0Points[0]);

        for (int index = 1; index < x0Points.length; index++) {
                polygon.lineTo(x0Points[index], y0Points[index]);
        }

        polygon.closePath();
            return polygon;
        }
    
        public static Shape bottomM(int x0,int y0){
            //Smaller Bottom M Point Instructions

               // Drawing instructions
            
            int x0Points[] = {x0+10, x0+31, x0+52, x0+73, x0+93, x0+90, x0+62, x0+52, x0+31, x0+13};
            int y0Points[] = {y0+73, y0+55, y0+73, y0+55, y0+73, y0+76, y0+73, y0+77, y0+73, y0+76};
            GeneralPath polygon = new GeneralPath(GeneralPath.WIND_NON_ZERO, x0Points.length);
            polygon.moveTo(x0Points[0], y0Points[0]);

            for (int index = 1; index < x0Points.length; index++) {
                    polygon.lineTo(x0Points[index], y0Points[index]);
            }

            polygon.closePath();
            
            return polygon;
        }
        public static Shape flame1(int x0,int y0){
            //First Triangle
               // Drawing instructions
            
            int x0Points[] = {x0+51, x0+40, x0+51};
            int y0Points[] = {y0+51, y0+37, y0+24};
            GeneralPath polygon = new GeneralPath(GeneralPath.WIND_NON_ZERO, x0Points.length);
            polygon.moveTo(x0Points[0], y0Points[0]);

            for (int index = 1; index < x0Points.length; index++) {
                    polygon.lineTo(x0Points[index], y0Points[index]);
            }

            polygon.closePath();
            
            return polygon;

        }
        public static Shape flame2(int x0, int y0){
            //Second Triangle
            
       // Drawing instructions
            
            int x0Points[] = {x0+51, x0+62, x0+51};
            int y0Points[] = {y0+35, y0+19, y0+5};
            GeneralPath polygon = new GeneralPath(GeneralPath.WIND_NON_ZERO, x0Points.length);
            polygon.moveTo(x0Points[0], y0Points[0]);

            for (int index = 1; index < x0Points.length; index++) {
                    polygon.lineTo(x0Points[index], y0Points[index]);
            }

            polygon.closePath();
            
            return polygon;
        }
}
    

Panel and Draw Calls:
CODE

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Random;

import javax.swing.JPanel;


public class Screener extends JPanel{

public Random generator = new Random();

   int x0 = generator.nextInt(1000);
   int y0 = generator.nextInt(500);
  

   public void Paint (Graphics g) {
      
       super.paintComponent(g);
      
        Graphics2D g2 = (Graphics2D) g;
      
         
        g2.draw(LogoDraw.topM(x0, y0));
        
        g2.draw(LogoDraw.bottomM(x0,y0));
        
        g2.draw(LogoDraw.flame1(x0,y0));
        
        g2.draw(LogoDraw.flame2(x0,y0));
        }
}
    



Again, thanks for any help.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 01:45PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month