class pla1 extends JFrame implements ActionListener
{
private JPanel x=new JPanel();
private JButton b1=new JButton("1");
private JButton b2=new JButton("2");
private JButton b3=new JButton("3");
private JButton b4=new JButton("4");
private JButton b5=new JButton("5");
private JTextField t=new JTextField(1);
private int terrain;
private int r;
final_class fc = new final_class();
public pla1(){
super("terrain");
getContentPane().add(x);
setSize(300,300);
// r=choi();
x.add(b1); b1.addActionListener((ActionListener) this);
x.add(b2); b2.addActionListener((ActionListener) this);
x.add(b3); b3.addActionListener((ActionListener) this);
x.add(b4); b4.addActionListener((ActionListener) this);
x.add(b5); b5.addActionListener((ActionListener) this);
x.add(t);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ev){
if(ev.getSource()==b1){t.setText("5");terrain=5;}
if(ev.getSource()==b2){t.setText("4");terrain=4;}
if(ev.getSource()==b3){t.setText("3");terrain=3;}
if(ev.getSource()==b4){t.setText("2");terrain=2;}
if(ev.getSource()==b5){t.setText("1");terrain=1;}
fc.passVart(terrain);
switch(terrain){
case 1: x.remove(b5);break;
case 2: x.remove(b4);break;
case 3:x.remove(b3);break;
case 4: x.remove(b2);break;
case 5: x.remove(b1);break;
default: break;}
//terrain=(int)Double.parseDouble(t.getText());
}
//public int choi(){if(terrain>0)return terrain;}
//public int choix(){return terrain;}
}
mport javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class pla2 extends JFrame implements ActionListener
{
private JPanel x=new JPanel();
private JButton b1=new JButton("1");
private JButton b2=new JButton("2");
private JButton b3=new JButton("3");
private JButton b4=new JButton("4");
private JButton b5=new JButton("5");
private int factor;
final_class fc = new final_class();
public pla2(){
super("factor");
getContentPane().add(x);
setSize(300,300);
x.add(b1); b1.addActionListener((ActionListener) this);
x.add(b2); b2.addActionListener((ActionListener) this);
x.add(b3); b3.addActionListener((ActionListener) this);
x.add(b4); b4.addActionListener((ActionListener) this);
x.add(b5); b5.addActionListener((ActionListener) this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ev){
if(ev.getSource()==b1){factor=1;}
if(ev.getSource()==b2){factor=2;}
if(ev.getSource()==b3){factor=3;}
if(ev.getSource()==b4){factor=4;}
if(ev.getSource()==b5){factor=5;}
fc.passVarf(factor);
}
public int choix(){return factor;}
}
public class final_class {
/**
* @param args
*/
private int factor;private int terrain;
private static int ter;
public void final_class(){}
public static void main(String[] args) {
// TODO Auto-generated method stub
pla1 p1=new pla1();
pla2 p2=new pla2();
p1.setVisible(true);
p2.setVisible(true);
// factor=p2.choix();System.out.println("fac "+factor);
//terrain=p1.choix();System.out.println("terrain "+terrain);
//System.out.println("terrain "+terrain);
}
public void passVarf(int f){
factor = f;
System.out.println(factor);
}
public void passVart(int t){
terrain = t;
System.out.println("factor"+factor);
//if(factor>0)§§§§ i cant get this thing to work i need both terrain and factor to have a value before they call thes e classes
{switch(terrain)
{
case 1: mx1 r1=new mx1();
r1.setVisible(true);break;
case 2: mx2 r2=new mx2();
r2.setVisible(true);break;
case 3: mx3 r3=new mx3();
r3.setVisible(true);break;
case 4: mx4 r4=new mx4();
r4.setVisible(true);break;
case 5: mx5 r5=new mx5();
r5.setVisible(true);break;
}
}
}
}

New Topic/Question
Reply




MultiQuote




|