SWING:
1. Jlabel
void setIcon(Icon icon);
Icon getIcon();
void setText(String text);
String getText();
2. jbutton
icon getIcon();
3. JtextField
Klasa JtextFiled słuzy do definiowania klatek, używanych zazwyczaj do wprowadzania jednowierszowych tekstów
void setText(String text);String getText()
4. JtextArea - Do definiowania edytorów
void setText(String text);void append(String text);void insert (String text, int pos);
void setEditable(boolean edit);
5. JcomboBox - Lista opadająca.
void addItem(Object item);void insertItemAt(Object item, int index);
void removeItem(Object item);void removeItemAt(int index);void removeAllItems();
int getSelectedIndex()Object getSelectedItem();
6. JcheckBox – do definiowania opcji odhaczanych
Int getStateChange() – dostarcza info o nowym stanie opcji: SELECTED, DESELECTED
7. JradioButton – OPCJE RADIOWE
Int getStateChange()
Przykład:
import java.awt.*;import java.awt.event.*;import javax.swing.*;
public class Daltonista extends JFrame implements ActionListener
{
JPanel p;JButton r,g,b,z;
public static void main(String [] args)
Daltonista f= new Daltonista("Czy jestes daltonistą ?",320,200);
f. setVisible(true);
}
public Daltonista(String s, int w,int h)
super(s);
setSize(w,h);
getContentPane().setLayout(new BorderLayout());
p = new JPanel();
JPanel pb = new JPanel();
pb.setLayout(new GridLayout(1,3));
getContentPane().add(p, BorderLayout.CENTER);
getContentPane().add(pb, BorderLayout.SOUTH);
r=new JButton("red"); g=new JButton("green"); b=new JButton("blue"); z=new JButton("Close");
r.addActionListener(this); g.addActionListener(this); b.addActionListener(this); z.addActionListener(this);
pb.add(r);pb.add(g);pb.add(b);pb.add(z);
public void actionPerformed (ActionEvent evt)
Object source = evt.getSource();
if (source == r)
{ p.setBackground(Color.red); }
else if (source == g)
{ p.setBackground(Color.green); }
else if (source == b)
{ p.setBackground(Color.blue); }
if (source == z)
{ System.exit(0); }
8. Jlabel
9. jbutton
10. JtextField
11. JtextArea - Do definiowania edytorów
12. JcomboBox - Lista opadająca.
13. JcheckBox – do definiowania opcji odhaczanych
14. JradioButton – OPCJE RADIOWE
rekin_80