Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » Java » repaint() Es will nicht so wie ich will ... Hilfe

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
02.06.2007, 22:46 Uhr
Sharp



Ich habe jetzt alles mögliche ausprobiert aber ich bekomme es einfach nicht hin das durch mein Event/meine Aktion mein Grafik Neu gemalt wird mit den neu gesetzten werden ...
Wenn ich wüsste wie das klappt könnt ich darauf aufbauen aber ich weiss es ja leider nicht

Also wer Rat weiss ich wäre mehr als glücklich


Code:
package projekt;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.*;

class Raum extends JPanel implements ActionListener
{    
    Rechteck r2;
    int iJTbr,iJTla;
    JTextArea jTinfo;
    
    JLabel jLbr;
    JLabel jLla;
    
    JTextField jTbr;
    JTextField jTla;
    
    JButton jBok;
    
    Content con;
    Main m;
    public Raum(Content con, Main m)      //JLabel Raum wird erstellt
    {
        jLbr = new JLabel("breite");
        jLla = new JLabel("längre");
        jTinfo = new JTextArea("Bitte geben sie \nunten Länge und Breite\n des Raumes ein");
        
        this.m=m;
        this.con=con;
        jTbr = new JTextField();
        
        
        jTla = new JTextField();
        

        jBok = new JButton("OK");
        
        setLayout(null);
        jTinfo.setBounds(20,20,110,50);
        add(jTinfo);
        jTinfo.setEditable(false);
        
        jLla.setBounds(20,85,110,15);
        add(jLla);
        jLbr.setBounds(20,140,110,15);
        add(jLbr);
        
        jTbr.setBounds(20,160,50,20);
        add(jTbr);
        jTla.setBounds(20,105,50,20);
        add(jTla);
        
        jBok.setBounds(20,190,50,30);
        add(jBok);
        jBok.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ae)
    {    
        int iJTbr= Integer.parseInt(jTbr.getText());
        int iJTla= Integer.parseInt(jTla.getText());
        con.setWerte(iJTbr, iJTla);
        con.repaint();
    }
}

class Objekte extends JPanel
{
    JComboBox jCmoe = new JComboBox();
    public Objekte()
    {
        setLayout(null);
        jCmoe.setBounds(20,20,50,10);
        add(jCmoe);
    }
}

class Content extends JPanel
{
    Vector vMoebel;
    Vector vKomponenten;
    Rechteck r,stuhl,tisch;
    Tab ta;
    int w1,w2;
     public Content()
     {
         this.vKomponenten=new Vector();
         this.vMoebel=new Vector();
         setBounds(155,5,600,550);
         setBackground(Color.BLACK);
     }
    
     void setTab(Tab ta)
     {
         this.ta=ta;
     }
    
     public void paintComponent(Graphics g)
     {
         stuhl = new Rechteck(20,20,20,20);
         this.vMoebel.add(stuhl);
         r = new Rechteck(0,0,w1,w2);
         this.vKomponenten.add(r);
         r =(Rechteck)vKomponenten.elementAt(0);
         g.drawRect(r.getPosx(), r.getPosy(), r.getBreite(), r.getHoehe());
         stuhl = (Rechteck)vMoebel.elementAt(0);
         g.drawRect(stuhl.getPosx(), stuhl.getPosy(), stuhl.getBreite(), stuhl.getHoehe());
     }
    
     void setWerte(int w1,int w2)
     {
         this.w1=w1;
         this.w2=w2;
     }
}

class Tab extends JTabbedPane
{
    Raum ra;
    Content con;
    Objekte obj = new Objekte();
    public Tab(Content con,Main m)
    {
        this.con=con;
        ra = new Raum(con,m);
        setBounds(0,0,150,600);
        addTab("Raum",ra);
        addTab("Objekte",obj);
        
    }
}

class Rechteck
{
    int posx, posy;
    int breite, hoehe;
    public Rechteck(int posx, int posy, int breite, int hoehe)
    {
        super();
        // TODO Auto-generated constructor stub
        this.posx = posx;
        this.posy = posy;
        this.breite = breite;
        this.hoehe = hoehe;
    }
    
    public Rechteck(int breite, int hoehe)
    {
        super();
        // TODO Auto-generated constructor stub
        this.breite = breite;
        this.hoehe = hoehe;
    }

    public int getBreite()
    {
        return breite;
    }
    public void setBreite(int breite)
    {
        this.breite = breite;
    }
    public int getHoehe()
    {
        return hoehe;
    }
    public void setHoehe(int hoehe)
    {
        this.hoehe = hoehe;
    }
    public int getPosx()
    {
        return posx;
    }
    public void setPosx(int posx)
    {
        this.posx = posx;
    }
    public int getPosy()
    {
        return posy;
    }
    public void setPosy(int posy)
    {
        this.posy = posy;
    }
}

public class Main extends JFrame


{
    Tab ta ;
    Content con;
    public Main()
    {
         con = new Content();
         ta = new Tab(con,this);

        setLayout(null);
        add(ta);
        add(con);
        setSize(800,600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setLocationRelativeTo(null);
        setVisible(true);
    }
    
    public static void main(String[] args)
    {
        Main bla = new Main();
    }
}

 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ Java ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: