Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] JTextfield and graphics  (Read 1048 times)
0 Members and 1 Guest are viewing this topic.
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Posted 2013-12-25 12:40:15 »

 Ok so im currenly having a problem implementing a JTextField onto a graphics windows/frame, some source code:

1  
2  
//intialise variable
JTextField port_textbox = new JTextField(15);


1  
2  
3  
4  
5  
6  
//adding in to my menu class:
  public MenuManagement() {
      Main.f.add(port_textbox);
      port_textbox.setBounds(100,100,100,100);
      port_textbox.setVisible(false);
   }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
   public void draw(Graphics2D g2d) {
         g2d.drawImage(getBgImg(), 0, 0, null);
         g2d.drawImage(getFog1(), fogX, fogY, null);
         g2d.setColor(Color.WHITE);
         g2d.drawString("IP: ", 100, 320);
         g2d.drawString("Port: ", 100, 350);
         g2d.drawString("Back", 100, 380);
         
         g2d.fillRect(0, 0, 500, 500);
         ip_textbox.setVisible(true);
         port_textbox.setVisible(true);

         g2d.drawRect(90, 300, 250, 30);
         g2d.drawImage(getTitleImage(), 60, 0, null);
             }


EDIT: forgot to say what the problem was, so what happens is...whenever i click a textbox to start typing information into it, the text box its starts a flickering effect. The text itself is being entered, i know this because when it flickers i can see the text for a short amount of time.

I love making games...
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #1 - Posted 2013-12-25 15:27:13 »

someone please?

I love making games...
Offline trollwarrior1
« Reply #2 - Posted 2013-12-25 15:34:00 »

What is the problem?.. You could try removing ".setVisible(true)" every time you draw something in that loop.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Genius Coder

Junior Member


Medals: 1
Exp: 4 years



« Reply #3 - Posted 2013-12-25 16:22:26 »

I have already tried that and it did nothing

I love making games...
Offline trollwarrior1
« Reply #4 - Posted 2013-12-25 16:33:00 »

I have already tried that and it did nothing

You didn't tell what the problem is? You just put down some NOT FULL code in front and asking for help. How are we supposed to know what the issue is? I can't even run this code to see the problem for myself. If you ask for help, don't forget to state the problem. That is very important.
Offline Axeman

Senior Member


Medals: 7



« Reply #5 - Posted 2013-12-25 16:43:18 »

If you want help here are some suggestions:

Try solving it yourself. Google is your friend.
Describe your problem in detail and what you have done to try and solve it.
Do not double post.
Be patient.

Remember that you are asking for someones time and effort so the least you can do is make it as easy as possibly for anybody that is willing to spend time on your problem.
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #6 - Posted 2013-12-25 21:22:19 »

I wasn't born a patient person, that's just unlucky
No, you teach yourself to be patient. Don't make excuses. When you post, use http://sscce.org/ as a guideline. In your code I don't know what getFog1() or getBgImg() is, or Main.f.
Offline trollwarrior1
« Reply #7 - Posted 2013-12-25 21:23:41 »

You should try adding JPanel onto JFrame. Then, add components, such as JTextField, onto the JPanel. Here is a short example.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
JFrame frame = new JFrame("JPanel Example.");
      JPanel panel = new JPanel();
      frame.add(panel, BorderLayout.CENTER);
     
      JTextField field = new JTextField(100);
      panel.add(field);
     
      frame.pack();
      frame.setVisible(true);
      frame.setLocationRelativeTo(null);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setResizable(false);


Try doing that and see if it works. If it doesn't, I'm sorry. I don't have anymore ideas. I would suggest to remove "field.setVisible(boolean b);" command from draw function.
Offline Stranger

Senior Member


Medals: 6



« Reply #8 - Posted 2013-12-26 07:45:58 »

In  addition to previous post:

The custom drawing is done by extending a JPanel and overrides the paintComponent() method.

1  
2  
3  
4  
5  
6  
7  
@Override
public void paintComponent(Graphics g) {  // graphics subsystem passes a Graphis2D subclass object as argument
  super.paintComponent(g);           // paint parent's background
  Graphics2D g2d = (Graphics2D) g;   // downcast the Graphics object back to Graphics2D
  // Perform custom drawing using g2d handle
  ......
}

Anton
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!