//Titel: Vorlesungsuebung //Version: 1,0 //Copyright: Copyright (c) 2013 //Autor: M. Wilhelm //Organisation: HS-Harz //Beschreibung: 1. Beispiel Thread import java.awt.*; import javax.swing.*; import java.awt.event.*; public class BspThread1 extends JFrame implements ActionListener { public static final long serialVersionUID=1; // global fuer addActionListener JButton bnBsp1 = new JButton("Bsp1"); JButton bnBsp2 = new JButton("Bsp2"); JButton bnBsp3 = new JButton("Bsp3"); JButton bnBsp4 = new JButton("Bsp4"); JButton bnBsp5 = new JButton("Bsp5"); JButton bnClose = new JButton("Close"); public BspThread1() { setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setGUI(); } private void setGUI() { setSize(700, 150); setLocation(400,100); setTitle("1. Threadbeispiel"); this.getContentPane().setLayout( new BorderLayout() ); JPanel panelBn = new JPanel(); panelBn.setLayout( new FlowLayout(FlowLayout.RIGHT) ); panelBn.add(bnBsp1); panelBn.add(bnBsp2); panelBn.add(bnBsp3); panelBn.add(bnBsp4); panelBn.add(bnBsp5); panelBn.add(bnClose); bnBsp1.setFont( new Font("Arial", Font.PLAIN,14) ); bnBsp2.setFont( new Font("Arial", Font.PLAIN,14) ); bnBsp3.setFont( new Font("Arial", Font.PLAIN,14) ); bnBsp4.setFont( new Font("Arial", Font.PLAIN,14) ); bnBsp5.setFont( new Font("Arial", Font.PLAIN,14) ); bnClose.setFont( new Font("Arial", Font.PLAIN,14) ); bnBsp1.addActionListener(this); bnBsp2.addActionListener(this); bnBsp3.addActionListener(this); bnBsp4.addActionListener(this); bnBsp5.addActionListener(this); bnClose.addActionListener(this); this.getContentPane().add( panelBn, BorderLayout.NORTH); } // setGUI public void actionPerformed(ActionEvent e) { if (e.getSource() == bnBsp1 ) { bnBsp1_click(); } if (e.getSource() == bnBsp2 ) { bnBsp2_click(); } if (e.getSource() == bnBsp3 ) { bnBsp3_click(); } if (e.getSource() == bnBsp4 ) { bnBsp4_click(); } if (e.getSource() == bnBsp5 ) { bnBsp5_click(); } if (e.getSource() == bnClose ) { System.exit(0); } } private void bnBsp1_click() { Thread1 th = new Thread1(); th.start(); } private void bnBsp2_click() { Thread2 th1 = new Thread2(1,5); th1.start(); Thread2 th2 = new Thread2(2,5); th2.start(); } private void bnBsp3_click() { Thread2[] th = new Thread2[5]; for (int i=0; i