Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8953823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:11:09+00:00 2026-06-15T14:11:09+00:00

I’ve been trying to make this graphics panel repaint but every time i call

  • 0

I’ve been trying to make this graphics panel repaint but every time i call to repaint, it does not update. I check the value that is supposed to be displayed in a system.out.println and the proper value is outputed in the log but the screen graphics will not update. Any suggestions/ help?

I have 3 classes(?)
This is my first class

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.awt.Font;
 import java.awt.Graphics;
 import java.net.URL;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
 import java.io.*;
 import javax.swing.Timer;
 public class ChromeNPlayerScreen extends JFrame implements ActionListener{
   public void actionPerformed(ActionEvent e){
     repaint();
   }
   public static void main(String[ ] args){
     DrawScreen dPnl = new DrawScreen();
     ChromeNPlayerScreen mScreen = new ChromeNPlayerScreen();
     Keys keyPress = new Keys();
     Timer update = new Timer(1000, mScreen);
      //    update.start();
     int screenNum=1;
     dPnl.importDialogue();

     mScreen.addKeyListener(keyPress);
     mScreen.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     mScreen.add(dPnl);
     mScreen.setSize(600,600);;
     mScreen.setVisible(true);
     mScreen.setResizable(false);
     mScreen.setLocation(200, 200);
   }
 }

This is my second class

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
 public class Keys extends KeyAdapter{
   DrawScreen dPnl = new DrawScreen();
   int scrnCount=0;
   public void keyPressed(KeyEvent e){
     int keyCode = e.getKeyCode();//Get key preseed
     if (keyCode ==e.VK_Z) {
       scrnCount++;
       dPnl.setText(scrnCount);
     }
   }
 }

And finally my third one

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.awt.Font;
 import java.awt.Graphics;
 import java.net.URL;
 import java.io.*;
 import javax.swing.Timer;

 public class DrawScreen extends JPanel {
   String picPath = "pictures/", scriptPath = "dialogue/";
   String out="ABC";
   String[] speech = new String[39];
   ClassLoader cl = DrawScreen.class.getClassLoader();
   URL imgURL1 = cl.getResource(picPath+"welcomeBG.png"),imgURL2 = cl.getResource(picPath+"dialogBox.png"),
     imgURL3 = cl.getResource(picPath+"Professor.png");
   Toolkit tk = Toolkit.getDefaultToolkit();
   Image imgBG = tk.createImage(imgURL1),
     imgDialog = tk.createImage(imgURL2),
     imgProfessor = tk.createImage(imgURL3);
   int screenCount=1;
   int scrn=1;
   public void paintComponent(Graphics g) {
     g.drawImage(imgBG,0,0,600,600,0,0,500,500, this);
     g.drawImage(imgDialog,-5,480,595,565,0,0,500,91, this);
     if (scrn==1)
     g.drawImage(imgProfessor,200,50,375,475,0,0,340,748, this);
     g.drawString(out, 25,515);
   }
   public void importDialogue(){
     Keys keyPress = new Keys();
     String [] fields; // array to store the "split" line read // individual field variables
     BufferedReader in=null; //variable representing the bufferedreader
     String line="A B 1"; //variable to read each line from the data file
     File f=new File(scriptPath+"newGameScript.txt"); //variable reprsenting the data file
     int count=1;
     try{
       in=new BufferedReader(new FileReader(f));
       System.out.println("File Opening");
     }
     catch (FileNotFoundException e){
       System.out.println("Problem finding File");
       return;
     }
     while(line!=null){
       try{
         line=in.readLine();
         if (line!=null){
           fields=line.split(":");
           speech[count]=(fields[0]);
           count++;
         }
       }
       catch (IOException e){
         System.out.println("Problem reading data from file");
       }
       if (line!=null){}
       out=speech[scrn];
     } 
     try{
       in.close();
       System.out.println("Closing File");
     }
     catch (IOException e){
       System.out.println("Problem Closing "+e);
     }
   }
   public void setText(int num){
     scrn=num;
     importDialogue();
     System.out.println(out);
     repaint();
   }
 }

As you can see that when i press the Z key, it is supposed to update the out on the DrawScreen with the next line. Well supposed to but it wont. it just says the first line from the text file which is “Hi there!”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:11:10+00:00Added an answer on June 15, 2026 at 2:11 pm

    You can find a major problem, and possibly the problem, just by using the text search capabilities of your browser on this page. I want you to use your browser to search for the String “new DrawScreen()” without the quotes of course. Ignoring my post, you’ll see that it occurs twice in your code above, once in the ChromeNPlayerScreen class:

    public class ChromeNPlayerScreen extends JFrame implements ActionListener{
       public void actionPerformed(ActionEvent e){
         repaint();
       }
       public static void main(String[ ] args){
         DrawScreen dPnl = new DrawScreen(); // ****
         // ...
    

    and once in the Keys class:

     public class Keys extends KeyAdapter{
       DrawScreen dPnl = new DrawScreen();
       // ....
    

    Understand that each time you call this you are creating a unique and independent DrawScreen object, and that making changes to the non-displayed DrawScreen object in your Keys class will have absolutely no effect on the displayed DrawScreen object shown in the ChromeNPlayerScreen class.

    A solution is to create a DrawString instance only once, probably in the ChromeNPlayerScreen class, and pass this same instance into your Key class via a constructor parameter. This way changes you make to the instance held by the Keys class will be reflected in the one and the same object that is displayed in the ChromeNPlayerScreen class.

     public class Keys extends KeyAdapter{
       DrawScreen dPnl;
    
       public Keys(DrawString dPnl) {
         this.dPnl = dPnl;
       }
    

    and

    public static void main(String[ ] args){
         DrawScreen dPnl = new DrawScreen();
         ChromeNPlayerScreen mScreen = new ChromeNPlayerScreen();
         Keys keyPress = new Keys(dPnl);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.