다 중 문자 낙하 실현

3516 단어 자바
package paint;
	
	import java.awt.Paint;
import java.awt.event.ActionEvent;
	import java.awt.event.ActionListener;
	import java.awt.event.KeyEvent;
	import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.JButton;
	import javax.swing.JFrame;
import javax.swing.JOptionPane;
	
	public class PaintMain {
		JFrame jFrame;
		String []strings= {"a","b","c","d","e","f"};
		public static void main(String[] args) {
			// TODO          
			PaintMain testMain=new PaintMain();
			testMain.initView();
		}
		
	public void initView()
	{
		
		jFrame =new JFrame();
		jFrame.setBounds(500, 500, 500, 500);
		jFrame.setLayout(null);
		ArrayListlist=new ArrayList();
		Data d1=new Data("a", 100, 100);
		list.add(d1);
		Data d2=new Data("b", 200, 100);
		list.add(d2);
		MyCanvas myCanvas=new MyCanvas(list);//   
		//                 
		myCanvas.setBounds(100,100, 500, 500);
		myCanvas.addKeyListener(new KeyListener() {
			//     
			@Override
			public void keyTyped(KeyEvent e) {
				// TODO          
				
			}
			
			@Override
			public void keyReleased(KeyEvent e) {
				// TODO          
				
			}
			
			@Override
			public void keyPressed(KeyEvent e) {
				//    
				// TODO          
				char ch=e.getKeyChar();//      ;
				String string =String.valueOf(ch);
				//1      
				//2    
				//3      
				//4    ,              ,  y  ,      
				for(int i=0;ilist=myCanvas.getList();
							for(int i=0;i

하위 함수 1
package paint;

import java.awt.Canvas;
import java.awt.Graphics;
import java.lang.reflect.Array;
import java.util.ArrayList;



public class MyCanvas extends Canvas{
	//          ,       ,   
	
	private ArrayList list=new ArrayList();
	public MyCanvas(ArrayListlist) {
		// TODO Auto-generated constructor stub
	
		this.list=list;
	}
	@Override
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
		super.paint(g);
		for(int i=0;i getList() {
		return list;
	}
	public void setList(ArrayList list) {
		this.list = list;
	}
}

하위 함수 2
package paint;

public class Data {
	private int xString;
	private int  yString;
	private String name;
	public Data(String name,int xString,int yString) {
		// TODO            
		this.xString=xString;
		this.yString=yString;
		this.name=name;
		
	}
	public int getxString() {
		return xString;
	}
	public void setxString(int xString) {
		this.xString = xString;
	}
	public int getyString() {
		return yString;
	}
	public void setyString(int yString) {
		this.yString = yString;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

}

좋은 웹페이지 즐겨찾기