codice:
import java.awt.*;
import java.awt.event.*;
import java.net.MalformedURLException;
import java.util.Vector;
import javax.swing.*;
public class App extends JFrame implements ActionListener, KeyListener, ItemListener, Runnable
{
//dichiarazione variabili non interessate al problema...
.
.
//fine dichiarazione variabili non interessate al problema...
private Starter s;
private Pi pi;
private JTextField orField, maxField, heField, moField, paField, exField, stField, tiField;
private Panel puPanel;
private List dirList;
private JButton sol, cont, re, sh;
private String[] algStrings = {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg"};
private JComboBox alg;
private Checkbox cbE, cbF;
private Panel pi;
public App(Starter _s)
{
super("Titolo");
s = _s;
setBackground(SystemColor.activeCaptionBorder);
.
.
.
CheckboxGroup cbGroup = new CheckboxGroup();
cbE = new Checkbox("e", cbGroup, true);
cbE.addItemListener(this);
cbF = new Checkbox("f", cbGroup, false);
cbF.addItemListener(this);
JPanel cbPanel = new JPanel();
cbPanel.setLayout(new FlowLayout());
cbPanel.add(new JLabel("Scegli:", JLabel.LEFT));
cbPanel.add(cbE);
cbPanel.add(cbF);
Panel algPanel= new JPanel();
algPanel.setLayout(new FlowLayout());
algPanel.add(new JLabel("Scegli:", JLabel.RIGHT));
alg= new JComboBox();
for(int i = 0; i < algStrings.length; i++)
alg.addItem (algStrings[i]);
algPanel.add(alg);
.
.
orField = new JTextField(10);
orField .addKeyListener(this);
orField .setBackground(Color.white);
JPanel orPanel = new JPanel();
orPanel.setLayout(new FlowLayout());
orPanel.add(new JLabel("Scegli:", JLabel.RIGHT));
orPanel.add(orField);
sol = new JButton("sol");
sol .addActionListener(this);
re= new JButton("re");
re.addActionListener(this);
sh= new JButton("sh");
sh.addActionListener(this);
sh.setEnabled(false);
cont = new JButton("cont");
cont.addActionListener(this);
cont.setEnabled(false);
maxField = new JTextField(10);
maxField .setBackground(Color.white);
JPanel maxPanel = new JPanel();
maxPanel .setLayout(new FlowLayout());
maxPanel .add(new JLabel("Scegli:", JLabel.RIGHT));
maxPanel .add(maxField);
maxPanel .add(sol);
maxPanel .add(re);
Panel userPanel = new Panel();
userPanel.setLayout(new GridLayout(4, 1));
userPanel.add(cbPanel);
userPanel.add(algPanel);
userPanel.add(orPanel);
userPanel.add(maxPanel);
JLabel title = new JLabel("Titolo", JLabel.CENTER);
title.setFont(new Font("sansserif", Font.BOLD, 20));
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new FlowLayout());
titlePanel.add(title);
Panel topPanel = new Panel();
topPanel.setLayout(new BorderLayout());
topPanel.add("North", titlePanel);
topPanel.add("South", new Box(userPanel, "Input", Box.LEFT));
pa = new Pa(s, SIZE);
Panel contPanel = new Panel();
contPanel.setLayout(new FlowLayout());
contPanel.add(cont);
Panel buttonPanel = new Panel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(sh);
buttonPanel.add(contPanel);
Panel contPanel = new Panel();
contPanel .setLayout(new FlowLayout());
contPanel .add(cont);
Panel buttonPanel = new Panel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(sh);
buttonPanel.add(contPanel);
puPanel = new Panel();
puPanel.setLayout(new FlowLayout());
puPanel.add(new Label());
puPanel.add(pi);
puPanel.add(new Label());
Panel puPanel = new Panel();
puPanel.setLayout(new BorderLayout());
puPanel.add("North", puPanel);
puPanel.add("South", buttonPanel);
Panel puButtonPanel = new Panel();
puButtonPanel.setLayout(new BorderLayout());
puButtonPanel.add("North", puPanel);
//da qui ci sono 6 JTextField, evito di riportarli
.
.
Panel infoPanel = new Panel();
infoPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 0, 1, 10);
gbc.anchor = GridBagConstraints.EAST;
gbc.gridwidth = 1;
gbc.weightx = 0;
gbc.fill = GridBagConstraints.NONE;
infoPanel.add(new Label("St:", Label.RIGHT), gbc);
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 100;
gbc.fill = GridBagConstraints.HORIZONTAL;
infoPanel.add(stField, gbc);
//così per tutti e 6 i JTextField
.
.
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridheight = GridBagConstraints.REMAINDER;
gbc.weightx = 100;
gbc.weighty = 100;
gbc.fill = GridBagConstraints.BOTH;
infoPanel.add(dirList, gbc);
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new BorderLayout());
centerPanel.add("West", new Box(puButtonPanel, "Pu", Box.LEFT));
centerPanel.add("Center", new Box(infoPanel, "Sol", Box.LEFT));
setLayout(new BorderLayout());
add("North", topPanel);
add("Center", centerPanel);
validate();
pack();
setResizable(false);
setVisible(true);
}
public void run()
{
.
.
}
private void prepareToRun()
{
.
.
cbE.setEnabled(false);
cbF.setEnabled(false);
alg.setEnabled(false);
orField.setEnabled(false);
maxField.setEnabled(false);
sol.transferFocus();
sol.setEnabled(false);
}
public void start()
{
.
.
}
public void actionPerformed(ActionEvent ae)
{
.
.
.
cbE.setEnabled(true);
cbF.setEnabled(true);
alg.setEnabled(true);
.
.
}
public static void main(String[] args)
{
App pa = new App(null);
}
}
In pratica il frame è composto da: