24. november 2004 - 15:38
#11
Her kommer den:
package Hjaelpetraener.guiKomponent;
import javax.swing.*;
import javax.swing.border.*;
import sun.java2d.Disposer;
import java.awt.*;
import java.awt.event.*;
//Panel under træning
public class training extends JPanel{
static String[] menuItems = {"Åbn","Gem","Udskriv","Opret øvelse"};
//Constructor
public training(Dimension contentDimension){
//Fysiske øvelser
JPanel warmUp = new JPanel();
warmUp.setBorder(new TitledBorder(new EtchedBorder(), "Fysisk"));
JScrollPane f = new JScrollPane();
JLabel firkant = new JLabel(" Firkant ");
firkant.setTransferHandler(
new TransferHandler("text"));
warmUp.add(firkant);
firkant.setToolTipText("Øvelsen firkant består i at gruppen deles op i hold á " +
"5 spiller. 5. spiller stilles ind i midten" +
" hvorså han skal få fat i bolden");
firkant.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
JLabel spmand = new JLabel(" Sprællemand ");
spmand.setTransferHandler(
new TransferHandler("text"));
warmUp.add(spmand);
JLabel smaaloeb = new JLabel(" Små løb ");
smaaloeb.setTransferHandler(
new TransferHandler("text"));
warmUp.add(smaaloeb);
//Fysiske øvelser
JPanel power = new JPanel();
power.setBorder(new TitledBorder(new EtchedBorder(), "Fysisk"));
JScrollPane p = new JScrollPane();
JLabel armh = new JLabel(" Armhævninger ");
armh.setTransferHandler(
new TransferHandler("text"));
power.add(armh);
JLabel maveb = new JLabel(" Mavebøjninger ");
maveb.setTransferHandler(
new TransferHandler("text"));
power.add(maveb);
JLabel ehop = new JLabel(" Engle hop ");
ehop.setTransferHandler(
new TransferHandler("text"));
power.add(ehop);
//Konditions øvelser
JPanel cond = new JPanel();
cond.setBorder(new TitledBorder(new EtchedBorder(), "Kondition"));
cond.add(new JScrollPane(new JTextArea("Her står øvelser...", 7, 35)));
//Tekniske øvelser
JPanel tech = new JPanel();
tech.setBorder(new TitledBorder(new EtchedBorder(), "Teknik"));
tech.add(new JScrollPane( new JTextArea("Her står øvelser...", 7, 35)));
//Højre panel
JPanel Right = new JPanel();
Right.setLayout(new BoxLayout(Right, BoxLayout.PAGE_AXIS));
Right.add(warmUp);
Right.add(power);
Right.add(cond);
Right.add(tech);
// Venstre panel
JPanel Left = new JPanel();
Left.setBorder(new TitledBorder(new EtchedBorder(), "Valgte øvelser"));
Left.setLayout(null);
Left.setSize(new Dimension(600,400));
// Enumeration labels
JLabel enum1 = new JLabel("1. ");
enum1.setBounds(11,15,25,30);
JLabel enum2 = new JLabel("2. ");
enum2.setBounds(11,40,25,30);
JLabel enum3 = new JLabel("3. ");
enum3.setBounds(11,65,25,30);
JLabel enum4 = new JLabel("4. ");
enum4.setBounds(11,90,25,30);
JLabel enum5 = new JLabel("5. ");
enum5.setBounds(11,115,25,30);
JLabel enum6 = new JLabel("6. ");
enum6.setBounds(11,140,25,30);
JLabel enum7 = new JLabel("7. ");
enum7.setBounds(11,165,25,30);
JLabel enum8 = new JLabel("8. ");
enum8.setBounds(11,190,25,30);
JLabel enum9 = new JLabel("9. ");
enum9.setBounds(11,215,25,30);
JLabel enum10 = new JLabel("10. ");
enum10.setBounds(5,240,25,30);
//Transferhandlers
JLabel oevListe1 = new JLabel("");
oevListe1.setBounds(25,15,590,30);
oevListe1.setTransferHandler(
new TransferHandler("text"));
Left.add(enum1);
Left.add(oevListe1);
Left.setLayout(null);
JLabel oevListe2 = new JLabel(" ");
oevListe2.setBounds(25,40,590,30);
oevListe2.setTransferHandler(
new TransferHandler("text"));
Left.add(enum2);
Left.add(oevListe2);
Left.setLayout(null);
JLabel oevListe3 = new JLabel(" ");
oevListe3.setBounds(25,65,590,30);
oevListe3.setTransferHandler(
new TransferHandler("text"));
Left.add(enum3);
Left.add(oevListe3);
Left.setLayout(null);
JLabel oevListe4 = new JLabel(" ");
oevListe4.setBounds(25,90,590,30);
oevListe4.setTransferHandler(
new TransferHandler("text"));
Left.add(enum4);
Left.add(oevListe4);
Left.setLayout(null);
JLabel oevListe5 = new JLabel(" ");
oevListe5.setBounds(25,115,590,30);
oevListe5.setTransferHandler(
new TransferHandler("text"));
Left.add(enum5);
Left.add(oevListe5);
Left.setLayout(null);
JLabel oevListe6 = new JLabel(" ");
oevListe6.setBounds(25,140,590,30);
oevListe6.setTransferHandler(
new TransferHandler("text"));
Left.add(enum6);
Left.add(oevListe6);
Left.setLayout(null);
JLabel oevListe7 = new JLabel(" ");
oevListe7.setBounds(25,165,590,30);
oevListe7.setTransferHandler(
new TransferHandler("text"));
Left.add(enum7);
Left.add(oevListe7);
Left.setLayout(null);
JLabel oevListe8 = new JLabel(" ");
oevListe8.setBounds(25,190,590,30);
oevListe8.setTransferHandler(
new TransferHandler("text"));
Left.add(enum8);
Left.add(oevListe8);
Left.setLayout(null);
JLabel oevListe9 = new JLabel(" ");
oevListe9.setBounds(25,215,590,30);
oevListe9.setTransferHandler(
new TransferHandler("text"));
Left.add(enum9);
Left.add(oevListe9);
Left.setLayout(null);
JLabel oevListe10 = new JLabel(" ");
oevListe10.setBounds(25,240,590,30);
oevListe10.setTransferHandler(
new TransferHandler("text"));
Left.add(enum10);
Left.add(oevListe10);
// Hele panelet
JPanel content = new JPanel();
content.setPreferredSize(contentDimension);
content.setLayout(new GridLayout(1,2));
content.add(Left);
content.add(Right);
// Mouse listener
MouseListener listener = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
JComponent c = (JComponent)e.getSource();
TransferHandler th = c.getTransferHandler();
th.exportAsDrag(c, e, TransferHandler.COPY);
}
};
firkant.addMouseListener(listener);
spmand.addMouseListener(listener);
smaaloeb.addMouseListener(listener);
armh.addMouseListener(listener);
maveb.addMouseListener(listener);
ehop.addMouseListener(listener);
add(content);
oevelsePopUp();
}
public void kaldKnap4(){
oevelsePopUp();
}
public void oevelsePopUp(){
JFrame oevelsePop = new JFrame("Opret øvelse");
JPanel oevelsePopLeft = new JPanel();
oevelsePopLeft.setLayout(null);
oevelsePopLeft.setBorder(new TitledBorder(new EtchedBorder(), "Menu"));
oevelsePopLeft.setBounds(10, 10, 150, 380);
JPanel oevelsePopRight = new JPanel();
oevelsePopRight.setLayout(null);
oevelsePopRight.setBorder(new TitledBorder(new EtchedBorder(), "Right"));
oevelsePopRight.setBounds(170, 10, 310, 380);
//Arrays der angiver hvad der skal være i de
String[] typeArray = {"Opvarmning", "Fysik", "Teknik", "Kondition"};
String[] svaerhedsgradArray = {"1 - Meget let", "2 - Let", "3 - Middel", "4 - Svær", "5 - Meget svær"};
String[] facilitetsArray = {"Fodboldbane", "Motionsrum"};
JTextField oevelseNavn = new JTextField("Navn på øvelsen");
oevelseNavn.setBounds(10, 20, 130, 30);
//Laver comboboxen "type" og indsætter elementer
JComboBox type = new JComboBox(typeArray);
type.setBounds(10, 60, 130, 30);
//Laver comboboxen "svaerhedsgrad" og indsætter elementer
JComboBox svaerhedsgrad = new JComboBox(svaerhedsgradArray);
svaerhedsgrad.setBounds(10, 100, 130, 30);
//Laver comboboxen "facilitet" og indsætter elementer
JComboBox facilitet = new JComboBox(facilitetsArray);
facilitet.setBounds(10, 140, 130, 30);
JTextField varighed = new JTextField("Varighed på øvelsen...");
varighed.setBounds(10, 180, 130, 30);
JTextPane oevelseTextPane = new JTextPane();
JScrollPane oevelseTxtFelt = new JScrollPane(oevelseTextPane);
oevelseTxtFelt.setBounds(10, 20, 290, 315);
JButton gemKnap = new JButton("Gem");
gemKnap.setBounds(80, 340, 110, 30);
ActionListener annullerKnapListener = new ActionListener() {
public void actionPerformed(ActionEvent e){
System.out.println("crap!!!!\n- Bailing OUT!!");
}
};
JButton annullerKnap = new JButton("Annuller");
annullerKnap.setBounds(190, 340, 110, 30);
oevelsePopLeft.add(oevelseNavn);
oevelsePopLeft.add(type);
oevelsePopLeft.add(svaerhedsgrad);
oevelsePopLeft.add(facilitet);
oevelsePopLeft.add(varighed);
oevelsePopRight.add(oevelseTxtFelt);
oevelsePopRight.add(gemKnap);
oevelsePopRight.add(annullerKnap);
Container cp = oevelsePop.getContentPane();
cp.add(oevelsePopLeft);
cp.add(oevelsePopRight);
cp.setLayout(null);
oevelsePop.setSize(500,440);
oevelsePop.setVisible(true);
annullerKnap.addActionListener(annullerKnapListener);
}
}