I have a school project which requires creating a GUI. I am using flow-layout for the first time, and cannot figure out what I should use to create an area where I can enter text. None of the classes I used before work with flow-Layout. It needs to be editable, be able to go to a string. I just can't find a class that will work.
Here is my code as is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class RedAliance extends JFrame
{
JRadioButton number;
JRadioButton name;
JRadioButton city;
JRadioButton state;
FlowLayout experimentLayout = new FlowLayout();
final String numberString = "By numer";
final String nameString = "By Name";
final String cityString = "By city";
final String stateString = "By State";
JButton search = new JButton("search");
public static void main(String[] args) {
/* Use an appropriate Look and Feel */
try
{
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
}
catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
catch (IllegalAccessException ex) {
ex.printStackTrace();
}
catch (InstantiationException ex) {
ex.printStackTrace();
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
/* Turn off metal's use of bold fonts */
UIManager.put("swing.boldMetal", Boolean.FALSE);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
public RedAliance(String name) {
super(name);
}
public void addComponentsToPane(final Container pane) {
final JPanel p = new JPanel();
p.setLayout(experimentLayout);
experimentLayout.setAlignment(FlowLayout.TRAILING);
JPanel controls = new JPanel();
controls.setLayout(new FlowLayout());
number = new JRadioButton(numberString);
number.setActionCommand(numberString);
number.setSelected(true);
name = new JRadioButton(nameString);
name.setActionCommand(nameString);
city = new JRadioButton(cityString);
city.setActionCommand(cityString);
state = new JRadioButton(stateString);
state.setActionCommand(stateString);
final ButtonGroup group = new ButtonGroup();
group.add(number);
group.add(name);
group.add(city);
group.add(state);
controls.add(number);
controls.add(name);
controls.add(city);
controls.add(state);
controls.add(search);
//Process the Apply component orientation button press
search.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String command = group.getSelection().getActionCommand();
String text= "";
if (command.equals("By Name")) { byName(text);}
else if (command.equals("By Numer")) {
}
else if(command.equals("By State")){
}
else if(command.equals("By City")){
}
else {}
//update the experiment layout
p.validate();
p.repaint();
}
});
pane.add(p, BorderLayout.CENTER);
pane.add(controls, BorderLayout.SOUTH); ;
}
private static void createAndShowGUI() {
RedAliance frame = new RedAliance("red"); //Create window
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.addComponentsToPane(frame.getContentPane());
frame.pack();
frame.setVisible(true);
}
public void byName(String n)//returns the info on a team with this name
{
}
public void byNumber(int n) //returns the info on a team with this number
{
}
public void byCity(String c)//returns the info on all teams in this city
{
}
public void byState(String s)//returns the info on all teams in this city
{
}
}