Hallöchen=)
Hab hioer ein kleines Problemchen und ich find dooferweise den Fehler nicht :bahnhof:
Ich habe ein JFrame in einer Klasse, welche eine innere Klasse beinhaltet, die von JPanel erbt, um zeichnen zu können.
Mein Problem ist nur, dass das Graphics erst so 1-2 sek nachdem der Frame geöffnet wurde angezeigt wird.... =(
Es wär wirklich sehr toll wenn ihr helfen könntet!
Hier der Quellcode:
	
	
	
	
	
		
	
Danke schonmal=)
			
			Hab hioer ein kleines Problemchen und ich find dooferweise den Fehler nicht :bahnhof:
Ich habe ein JFrame in einer Klasse, welche eine innere Klasse beinhaltet, die von JPanel erbt, um zeichnen zu können.
Mein Problem ist nur, dass das Graphics erst so 1-2 sek nachdem der Frame geöffnet wurde angezeigt wird.... =(
Es wär wirklich sehr toll wenn ihr helfen könntet!
Hier der Quellcode:
		Java:
	
	package de.jonas.dayreport;
public class DayReportTopicManager {
	JFrame f;
	JLabel topicsLabel;
	Color bg = Color.WHITE;
	ArrayList<String> topics = new ArrayList<String>();
	Font fontMain = new Font("Aial", Font.PLAIN, 30);
	InitialiseTopics topicGraphics;
	
	int mainTopicWidth, mainTopicHeight;
	int xMain, yMain;
	
	String mainTopic, prevTopic, nextTopic;
	
	int currentTopic = 0;
	public DayReportTopicManager() {
		f = new JFrame("Themenmanager");
		f.setSize(400, 600);
		f.setLocationRelativeTo(null);
		f.getContentPane().setBackground(bg);
		f.setLayout(null);
				
		fillArray();
		prevTopic="";
		mainTopic=topics.get(currentTopic);
		nextTopic=topics.get(currentTopic+1);
		createTopicsAndSubtopics();
		f.add(topicGraphics);
		f.setResizable(false);   
		f.setVisible(true);
	}
	public void createTopicsAndSubtopics() {
		topicGraphics = new InitialiseTopics();
		topicGraphics.setBounds(50, 10, 300, 80);
	}
	
	public void fillArray(){
		//Später aus Datei:
		topics.add("Einnahmen");
		topics.add("Ausgaben");
		topics.add("Sport");
		topics.add("Liebe");
		
	}
	public class InitialiseTopics extends JPanel {
		private static final long serialVersionUID = 1L;
		public void paintComponent(Graphics g ){
			super.paintComponent(g);
			setPreferredSize(new Dimension(300,80));
		    this.setBackground(Color.RED);		   
		    
		    paintStrings(g);
		}
		
		public void paintStrings(Graphics g){
			g.drawLine(0, 40, 300, 40);
	    		g.setFont(fontMain);
	    	
	    		mainTopicWidth =g.getFontMetrics().stringWidth(mainTopic);
	    		mainTopicHeight =g.getFontMetrics().getHeight();
	    		xMain = 150-mainTopicWidth/2;
	    		yMain = 40+mainTopicHeight/2;
	    		g.drawString(mainTopic, 100, 100);
		}
	}
	
}Danke schonmal=)
 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		