carookee - group communication for you
Home / JavaForum / Swing + AWT
Infos   |   Features   |   Gold-Edition   |   Kundenservice   
java
  Übersicht
  Forum
Beginner
Java allgemein
JDBC
JNI
Networking
Online-Ressourcen
Swing + AWT
XML
Meckerecke
  Mitglieder
LOGIN





· Passwort vergessen
· Kostenlos anmelden
  Information
  Demo
  Features
  Im Vergleich
  Anmeldung
SUCHE
Beiträge, Foren oder Verfasser finden:
  Kundenservice
  Impressum
  Datenschutz
  AGB
Status
4.032 User online
1 User eingeloggt
 

Beiträge
   Antworten     Neuer Beitrag    

Beitrag 114 von 1460 (8%) |<   <   >   >|

Autor Fridolin
Datum 04.07.04, 13:23
Betreff paint über token aus streamtokenizer


Hallo,
ich suche hilfe zu folgendem problem ich will aus einer
textdatei abfragen welcher buchstabe darin enthalten ist
und dafür ein rechteck mit einer bestimmten farbe zeichnen
das graphics objekt ist eine instanzvariable und kann somit
von überall aufgerufen werden, mein problem ist nur falls
es das einzige ist das nichts gezeichnet wird

das ganze ist eine swing applikation


import java.awt.*;
import java.io.*;
import javax.swing.*;

public class Kariert extends JFrame
{
    private Graphics dbg;
    StreamTokenizer tokenizer;
    //BufferedReader in;
    FileInputStream is;
    BufferedReader r;
    //Reader r
    String board[][] = new String[18][42];
    String message = "";
    int boardint[][] = new int[18][42];
    int count1 = 0;
    int count2 = 0;
    int boardx = 0;
    int boardy = 0;
    int blocksizex = 7;
    int blocksizey = 16;
    int token;
    
    public Kariert()
    {
        
        
        try
        {
            
             //in = new BufferedReader(
            //new FileReader("Kopie von Mappe.txt"));
            //tokenizer = new StreamTokenizer(in);
            is = new FileInputStream("Kopie von Mappe.txt");
            r = new BufferedReader(
            new InputStreamReader(is));
            tokenizer = new StreamTokenizer(r);
            tokenizer.parseNumbers();
            tokenizer.wordChars('c', 'c');
            tokenizer.wordChars('w', 'w');
            tokenizer.wordChars('n', 'n');
            tokenizer.wordChars('s', 's');
            tokenizer.wordChars('e', 'e');
            //tokenizer.wordChars('0', ' ');
            tokenizer.ordinaryChars(0, ' ');
            tokenizer.whitespaceChars(' ',' ');
             tokenizer.eolIsSignificant(true);
             tokenizer.slashStarComments(true);
             tokenizer.slashSlashComments(true);
            
            while ((token = tokenizer.nextToken()) != StreamTokenizer.TT_EOF)
            {
                 switch (token)
                 {
                     case StreamTokenizer.TT_WORD:
                     message = "Word: " + tokenizer.sval;
                     board[count1][count2] = tokenizer.sval;
                    count2++;
                     break;
                     case StreamTokenizer.TT_EOL:
                     count1++;
                    break;
                    case StreamTokenizer.TT_EOF:
                     count1 = 0;
                     count2 = 0;
                    break;
                    //default:
                    //char ch = (char)tokenizer.ttype;
                    //break;
                 }
            }
            for(count1 = 0; count1 <= 16; count1++)
            {
                for(count2 = 0; count2 <= 40; count2++)
                {
                    boardint[count1][count2] = Integer.parseInt(board[count1][count2]);
                }
            }
            for(count1 = 0; count1 <= 16; count1++)
            {
                 if(count1 != 0)
                {
                    boardy+=blocksizey;
                    boardx = 0;
                }
                for(count2 = 0; count2 <= 40; count2++)
                {
                    switch (boardint[count1][count2])
                    {
                         case 'n':
                         if(dbg == null)
                         {
                             dbg = getGraphics();
                         }
                         dbg.setColor(Color.blue);
                         break;
                         default:
                         if(dbg == null)
                         {
                             dbg = getGraphics();
                         }
                         dbg.setColor(Color.black);
                         break;
                    }
                    
                    paint(dbg);
                    boardx+=blocksizex;
                    
                }
            }
        }
        catch (IOException e) { }
    }
    
    public void paint(Graphics g)
    {
        g.drawRect(boardx,boardy,blocksizex,blocksizey);
        g.fillRect(boardx,boardy,blocksizex,blocksizey);
    }
    
    public void update(Graphics g)
    {
        paint(g);
    }
    
    public static void main(String args[])
    {
        Kariert neu = new Kariert();
        neu.setSize(294,288);
        neu.setLocation(100,100);
        neu.setVisible(true);
    }
}



Diskussionsverlauf:
paint über token aus streamtokenizer
    Re: paint über token aus streamtokenizer

 Auf diesen Beitrag antworten
 Neuen Beitrag verfassen


|<   <   >   >|

                                                                                                                                                                                                                           

Impressum  · Datenschutz  · AGB  · Infos  · Presse
Ein modernes Forum: teamturn.com