GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes addCheckbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "addCheckbox" Watch "addCheckbox" New topic
Author

addCheckbox

alec stewart stewart
Ranch Hand

Joined: Dec 23, 2003
Posts: 71
what is wrong with my program it shows errors whereever i am using addCheckbox and add methods
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
public class TextBoundaryTest
{
public static void main(String [] args)
{
JFrame frame=new TextBoundaryFrame();
frame.show();
}
}
class TestBoundaryFrame extends JFrame
{
public TestBoundaryFrame()
{
setSize(400, 400);
setTitle("International");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
ActionListener listener = new ActionListener(){public void actionPerformed(ActionEvent event){updateDisplay();}};
JPanel p= new JPanel();
addCheckBox(p,characterCheckBox,cbGroup,listener,false);
addCheckBox(p,wordCheckBox,cbGroup,listener,false);
addCheckBox(p,lineCheckBox,cbGroup,listener,false);
addCheckBox(p,sentenceCheckBox,cbGroup,listener,true);
getContentPane().setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.fill=GridBagConstraints.NONE;
gbc.anchor=GridBagConstraints.EAST;
add(new JLabel("Locale"),gbc,0,0,1,1);
gbc.anchor=GridBagConstraints.WEST;
add(localcombo,gbc,1,0,1,1);
add(p,gbc,0,1,2,1);
gbc.fill=GridBagConstraints.BOTH;
gbc.weighty=100;
add(new JScrollPane(inputText),gbc,0,2,2,1);
add(new JScrollPane(outputText),gbc,0,3,2,1);
locales = BreakIterator.getAvailableLocales();
for(int i=0;i<locales.length;i++)
localcombo.setSelectedItem(Locale.getDefault().getDisplayName());
localcombo.setSelectedItem(Locale.getDefault().getDisplayName());
inputText.setText("The quick, brown fox jump-ed over the lazy dog And...what happened?");
updateDisplay();
}
public void addCheckBox(Container c, GridBagConstraints gbc,int x,int y,int w,int h)
{
gbc.gridx=x;
gbc.gridy=y;
gbc.gridwidth=w;
gbc.gridheight=h;
getContentPane().add(c,gbc);
}
public void updateDisplay()
{
Locale currentLocale=locales[localcombo.getSelectedIndex()];
BreakIterator currentBreakIterator= null;
if(characterCheckBox.isSelected())
currentBreakIterator=BreakIterator.getCharacterInstance(currentLocale);
else if(wordCheckBox.isSelected())
currentBreakIterator=BreakIterator.getWordInstance(currentLocale);
else if(lineCheckBox.isSelected())
currentBreakIterator=BreakIterator.getLineInstance(currentLocale);
else if(sentenceCheckBox.isSelected())
currentBreakIterator=BreakIterator.getSentenceInstance(currentLocale);
String text = inputText.getText();
currentBreakIterator.setText(text);
outputText.setText("");
int from=currentBreakIterator.first();
int to;
while((to=currentBreakIterator.next())!=BreakIterator.DONE)
{
outputText.append(text.substring(from,to)+"|");
from=to;
}
outputText.append(text.substring(from));
}
private Locale [] locales;
private BreakIterator currentBreakIterator;
private JComboBox localcombo=new JComboBox();
private JTextArea inputText=new JTextArea(6,40);
private JTextArea outputText=new JTextArea(6,40);
private JCheckBox characterCheckBox=new JCheckBox("charcater");
private JCheckBox wordCheckBox=new JCheckBox("word");
private JCheckBox lineCheckBox=new JCheckBox("line");
private JCheckBox sentenceCheckBox=new JCheckBox("sentence");
private ButtonGroup cbGroup=new ButtonGroup();
}
Glenn Castro
Ranch Hand

Joined: Aug 24, 2003
Posts: 78
I think, the methods you used have invalid arguments. Like in the case of add method, you should specify the components only as a parameter.
Example: add(new JScrollPane(inputText));
Also in your addCheckBox method. Try to follow what's on the API.


Glenn Castro<br />Sun Certified Web Component Developer
 
GeeCON Prague 2014
 
subject: addCheckbox