PutiActionListener.java :  » OSGi » gadget-on-osgi » jp » co » withone » gadget » putiputi » base » Java Open Source

Java Open Source » OSGi » gadget on osgi 
gadget on osgi » jp » co » withone » gadget » putiputi » base » PutiActionListener.java
/*
 * Copyright 2010 WithOne Co. Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jp.co.withone.gadget.putiputi.base;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 * 
 * 
 * @author Sasaki Katsuyuki
 *
 */
public class PutiActionListener extends JFrame implements ActionListener{

  int number;
  URL url;
  ImageIcon icon;
  
  private static int counter=0;
  

  /**
   * 
   * 
   */
  @Override
  public void actionPerformed(ActionEvent e) {

    counter++;
    number = (int)(Math.random()*1000);
    
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    PutiBody.frames.add(frame);
    
    JLabel putiLa;
    
    if(number < 51){
      putiLa = new JLabel(counter + "");
      frame.setSize(50,50);
      frame.setLocation((int)(PutiBody.dimension.width * Math.random()), (int)(PutiBody.dimension.height * Math.random()));
      
      
    }else if((number > 50 )&& (number < 61)){
      
      url = getClass().getClassLoader().getResource("img/fuchi.jpg");
      icon = new ImageIcon(url);
      putiLa = new JLabel(icon);
      frame.setSize(300,300);
      frame.setLocation((int)(PutiBody.dimension.width * Math.random()), (int)(PutiBody.dimension.height * Math.random()));
      
    }else if (number == 61) {

      url = getClass().getClassLoader().getResource("img/putin.jpg");
      icon = new ImageIcon(url);
      putiLa = new JLabel(icon);
      frame.setSize(PutiBody.dimension.width,PutiBody.dimension.height);
      frame.setLocationRelativeTo(null);

    }else if((number > 61 )&& (number < 66)){

      url = getClass().getClassLoader().getResource("img/welch.jpg");
      icon = new ImageIcon(url);
      putiLa = new JLabel(icon);
      frame.setSize(200,350);
      frame.setLocation((int)(PutiBody.dimension.width * Math.random()), (int)(PutiBody.dimension.height * Math.random()));

    }else if (number==66 || number==67) {

      url = getClass().getClassLoader().getResource("img/obuchi.jpg");
      icon = new ImageIcon(url);
      putiLa = new JLabel(icon);
      frame.setSize(PutiBody.dimension.width,PutiBody.dimension.height);
      frame.setLocationRelativeTo(null);
      
    }else{
      putiLa = new JLabel("");
      frame.setSize(50,50);
      frame.setLocation((int)(PutiBody.dimension.width * Math.random()), (int)(PutiBody.dimension.height * Math.random()));
    }

    contentPane.add(putiLa);
    
    frame.setResizable(false);
    frame.setVisible(true);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.