1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ConstructionPanel extends JPanel implements MouseListener {
int counter;
int width, height;
Entity[] entity_list;
public ConstructionPanel(){
Toolkit tk=Toolkit.getDefaultToolkit();
this.setPreferredSize(new Dimension(tk.getScreenSize().width/2,3*tk.getScreenSize().width/4));
width= tk.getScreenSize().width;
height=tk.getScreenSize().height;
this.setBackground(Color.white);
this.setLayout(null);
counter=0;
entity_list=new Entity[10];
add_arrow=false;
connect=false;
first=false;
second=true;
ind_first=-1;
ind_sec=-1;
connexions= new int[10][10];
}
public void add(Map map){
int[] t= {20 ,20};
entity_list[counter]=new Entity(this,map,map.getPosition(),counter,map.getType(), t,width/10,height/5);
map.setPanel_identifier(counter);
entity_list[counter].addMouseListener(this);
this.add(entity_list[counter]);
entity_list[counter].setLocation(20,20);
this.validate();
this.repaint();
counter+=counter;
}
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("test");
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
class Entity extends JPanel{
ConstructionPanel constr;
Map map;
String title;
int position_as_entity,position_as_map,width,height,wd,type,oldX,oldY ;
int[] coordinates;
Graphics g;
//EntityListener listen;
public Entity(ConstructionPanel constructionpanel,Map map,int position_as_map,int position_as_entity,int type,int[] coordinates,int width, int height){
this.constr=constructionpanel;
this.map=map;
this.position_as_map=position_as_map;
this.position_as_entity=position_as_entity;
this.type=type;
this.coordinates=coordinates;
this.width=width;
this.height=height;
title=map.getTitle();
//this.setPreferredSize(new Dimension(width,height));
//this.addMouseListener(listen = new EntityListener());
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawString(title, 20, 20);
g.drawLine(1, 1,width-2 ,1);
g.drawLine(width-2, 0,width-2 ,height-2);
g.drawLine(width-2, height-2,1 , height-2);
g.drawLine(1, height-2,1 ,1);
}
} |
Partager