Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a code which creates graphical shapes and displays on the screen with the fonts/strings written on it.

To do this I extended the Frame class, and its paint() method was overriden and graphical shapes were created and rendered on the screen.

Now I wanted to display different string when different language option is selected.

I use DOM parser to parse different language texts (xml files that has different language tag-values) and its rendered beautifully on the screen too.

I was manually writing in the code to choose this language file to parse and render it on the screen

I wanted to use radio buttons to choose which language file to parse, but when I try to add these radio buttons to the screen, the buttons are flowing and it jitters, flickers.

Existing Code:

Class Apple extends Frame 
{
private Shape A = new RoundRectangle2D.Double(20,30,100,150,10,10);
private Shape B = new RoundRectangle2D.Double(20,200,100,150,10,10);

Apple()
{
setTitle("Fruits");
setBackground(Color.BLACK);
setSize(700,700);
setVisible(true);
}
@Override
public void paint(Graphics graphics)
{
super.paint(graphics);
//Code for drawing Graphical Shapes..
//Code for setting font into the graphical shapes..
}
}


This code works perfectly fine,
But I want to insert few radio buttons to this screen for choosing language (for the fonts that are displayed in shapes).

So I did this

Class Apple extends Frame 
{
private Shape A = new RoundRectangle2D.Double(20,30,100,150,10,10);
private Shape B = new RoundRectangle2D.Double(20,200,100,150,10,10);
CheckboxGroup languageSelector = new CheckboxGroup();  
Checkbox selectEnglish = new Checkbox("English", languageSelector,true);  
Checkbox selectHindi = new Checkbox("Hindi", languageSelector, false);
Apple()
{
selectEnglish.setBounds(300,100,70,50);
selectHindi.setBounds(350,100,70,50);
setTitle("Fruits");
setBackground(Color.BLACK);
setSize(700,700);
setVisible(true);
}
@Override
public void paint(Graphics graphics)
{
super.paint(graphics);
//Code for drawing Graphical Shapes..
//Code for setting font into the graphical shapes..
add(selectEnglish)
add(selectHindi)
 }
 }


What I have tried:

If I add radio buttons to the Frame directly in the Constructor it will ignore the overriden paint method and will only render the radio buttons on the screen and not the shapes..

So I thought I could add radio buttons to the frame through the overridden paint method itself, but the buttons are continuously flickering over the screen.
Posted
Updated 18-Jan-17 20:38pm
v3
Comments
Richard MacCutchan 19-Jan-17 4:45am    
You should add the controls to the JFrame at the beginning of the application or in the constructor, not in the paint method.
GaneshRfromSpace 19-Jan-17 23:17pm    
The sequence was wrong. I had a keylistener for the shapes in my constructor. I added the radio buttons at the end of the constructor and it worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900