package aufgabe3;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.BorderLayout;
/**
*
Überschrift: Aufgabe3</p>
*
Organisation: KOMMA </p>
*
* @author T.S.K
* @version 1.0
*/
public class Aufgabe3 extends JApplet implements MouseListener{
boolean isStandalone = false;
JTabbedPane jTabbedPane1 = new JTabbedPane();
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
Balken19 balken= new Balken19();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JTextField jTextField4 = new JTextField();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTextField jTextField5 = new JTextField();
JTextField jTextField6 = new JTextField();
JTextField jTextField7 = new JTextField();
JTextField jTextField8 = new JTextField();
JLabel jLabel7 = new JLabel();
//Parameterwert holen
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Das Applet konstruieren
public Aufgabe3() {
}
//Das Applet initialisieren
public void init() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
//Initialisierung der Komponenten
private void jbInit() throws Exception {
this.getContentPane().setBackground(Color.lightGray);
this.setSize(new Dimension(600, 404));
this.getContentPane().setLayout(borderLayout1);
jPanel1.setLayout(null);
jPanel1.setBackground(Color.lightGray);
jPanel2.setBackground(Color.lightGray);
jPanel2.setLayout(null);
jPanel3.setBackground(Color.lightGray);
jPanel3.setLayout(null);
jLabel1.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jLabel1.setToolTipText("");
jLabel1.setText(
"a) \tWie oft wurde bei der ersten Versuchsrunde ‚C‘ geworfen?");
jLabel1.setBounds(new Rectangle(25, 22, 512, 26));
jLabel2.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jLabel2.setToolTipText("");
jLabel2.setText(
"b) \tWie oft wurde bei der letzten Versuchsrunde ‚B‘ geworfen?");
jLabel2.setBounds(new Rectangle(25, 101, 512, 26));
jLabel3.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jLabel3.setText(
"<html><body>c) Wie oft wurden zusammengezählt bei der zweiten Versuchs-
    runde ‚A‘ und ‚D‘ geworfen? </body></html>");
jLabel3.setBounds(new Rectangle(25, 182, 552, 39));
jLabel4.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jLabel4.setText(
"<html><body>d) Wie oft wurde bei der ersten Runde ‚A‘ öfter geworfen als bei
    der zweiten Runde?</body></html> ");
jLabel4.setBounds(new Rectangle(25, 274, 537, 39));
jTextField1.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jTextField1.setForeground(Color.blue);
jTextField1.setHorizontalAlignment(SwingConstants.CENTER);
jTextField1.setBounds(new Rectangle(48, 58, 70, 28));
jTextField2.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jTextField2.setForeground(Color.blue);
jTextField2.setHorizontalAlignment(SwingConstants.CENTER);
jTextField2.setBounds(new Rectangle(48, 135, 70, 28));
jTextField3.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jTextField3.setForeground(Color.blue);
jTextField3.setHorizontalAlignment(SwingConstants.CENTER);
jTextField3.setBounds(new Rectangle(48, 232, 70, 28));
jTextField4.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jTextField4.setForeground(Color.blue);
jTextField4.setHorizontalAlignment(SwingConstants.CENTER);
jTextField4.setBounds(new Rectangle(48, 323, 70, 28));
jLabel5.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jLabel5.setText(
"e) \tWie oft wurden in allen drei Runden insgesamt geworfen?");
jLabel5.setBounds(new Rectangle(33, 76, 520, 28));
jLabel6.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jLabel6.setText("<html><body>A
B
C
D</body></html>");
jLabel6.setBounds(new Rectangle(93, 135, 31, 157));
jTextField5.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jTextField5.setForeground(Color.blue);
jTextField5.setHorizontalAlignment(SwingConstants.CENTER);
jTextField5.setBounds(new Rectangle(132, 138, 96, 28));
jTextField6.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jTextField6.setForeground(Color.blue);
jTextField6.setHorizontalAlignment(SwingConstants.CENTER);
jTextField6.setBounds(new Rectangle(132, 179, 96, 28));
jTextField7.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jTextField7.setForeground(Color.blue);
jTextField7.setHorizontalAlignment(SwingConstants.CENTER);
jTextField7.setBounds(new Rectangle(132, 223, 96, 28));
jTextField8.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jTextField8.setForeground(Color.blue);
jTextField8.setHorizontalAlignment(SwingConstants.CENTER);
jTextField8.setBounds(new Rectangle(132, 264, 96, 28));
balken.setBounds(new Rectangle(40, 100, 360, 220));
jLabel7.setFont(new java.awt.Font("Verdana", Font.PLAIN, 16));
jLabel7.setText(
"<html><body>e) \tTrage in einem Säulendiagramm auf, wie oft ‚A‘, ‚B‘, ‚C‘ und
" +
"    ‚D‘ in den einzelnen Runden insgesamt geworfen wurden,
    indem Du " +
"die Balken entsprechend verschiebst?");
jLabel7.setBounds(new Rectangle(22, 14, 552, 64));
this.getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);
balken.setBounds(40,100,360,220);
balken.addMouseListener(this);
jTabbedPane1.add(jPanel1, "Teil1");
jPanel1.add(jLabel1);
jPanel1.add(jTextField1);
jPanel1.add(jLabel2);
jPanel1.add(jTextField2);
jPanel1.add(jLabel3);
jPanel1.add(jTextField3);
jPanel1.add(jLabel4);
jPanel1.add(jTextField4);
jTabbedPane1.add(jPanel2, "Teil2");
jPanel2.add(balken, null);
jPanel2.add(jLabel7);
jTabbedPane1.add(jPanel3, "Teil3");
jPanel3.add(jLabel5);
jPanel3.add(jTextField8);
jPanel3.add(jLabel6);
jPanel3.add(jTextField7);
jPanel3.add(jTextField6);
jPanel3.add(jTextField5);
}
//Applet-Information
public String getAppletInfo() {
return "Applet-Informationen";
}
//Parameter-Infos holen
public String[][] getParameterInfo() {
return null;
}
//static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
}
}
class Balken19 extends JComponent
{
/**
*
*/
private static final long serialVersionUID = 1L;
int x0=40;
int y0=170;
int xl=310;
int yl=170;
int einheit=28;
int[] yp=new int[15];
int a=21;
int b=20;
int c=30;
int[] pfeilx={x0,x0-6,x0+6};
int[] pfeily={y0-yl,y0-yl+10,y0-yl+10};
Color[] Mycolor={Color.RED,Color.GREEN,Color.YELLOW,Color.BLUE,Color.LIGHT_GRAY};
int[] Zahl={4,0,4,2,0,1,3,4,2,0,2,3,4,1,0};
String anweisung ="normal";
public boolean kreuz=false;
TextField text7=new TextField("",10);
Font f,m,n;
int anzahl=15;
String[] Buchstab={"A","B","C","D",""};
public void Balken19()
{
}
public void paintComponent(Graphics g)
{
setSize(360,220);
setLayout(null);
setBackground(Color.LIGHT_GRAY);
f = new Font("",Font.ROMAN_BASELINE,30);
n = new Font("",Font.ROMAN_BASELINE,20);
for(int i=0;i<anzahl;i++){
yp[i]=1;
}
g.setFont(new Font("Verdana",Font.PLAIN,16));
g.drawString("1. Runde",50,220);
g.drawString("2. Runde",156,220);
g.drawString("3. Runde",262,220);
// Achse bezeichnen
g.setColor(Color.black);
m=g.getFont();
g.setFont(new Font("Verdana",Font.PLAIN,14));
for(int i=0;i<(yl/einheit)-1;i++){
for(int s=0;s<xl/2;s++)
{
g.setColor(Color.GRAY);
g.drawLine(x0+s*2,y0-i*einheit-einheit,x0+(s+1)*2,y0-i*einheit-einheit);
s=s+2;
}
g.setColor(Color.BLACK);
g.drawLine(x0-15,y0-i*einheit-einheit,x0+10,y0-i*einheit-einheit);
g.drawString(Integer.toString(i),x0-40,y0-i*einheit+5);
}
g.setFont(new Font("Verdana",Font.PLAIN,14));
for(int i=0;i<anzahl;i++){
g.drawString(Buchstab[i%5],x0+i*a+12,y0+20);
}
g.drawLine(x0,y0,x0,y0-yl);
g.drawLine(x0,y0,x0+xl,y0);
//balken bezeichnen
m=g.getFont();
if(anweisung=="Loesung")
{
for(int i=0;i<anzahl;i++)
{
if(i%5!=4){
g.setColor(Mycolor[i%5]);
g.fillRect(x0+i*a+30,y0-Zahl[i]*einheit,b,Zahl[i]*einheit);
g.setColor(Color.BLACK);
//g.drawString(Art[i],x0+i*a+30,y0+30);
g.drawString(Integer.toString(Zahl[i]),x0+i*a+45,y0-10);
}
anweisung="normal";
}
}else if(anweisung.equals("normal"))
{
for(int i=0;i<anzahl;i++)
{
if(i%5!=4){
g.setColor(Mycolor[i%5]);
g.fillRect(x0+i*a+7,y0-yp[i]*einheit,b,yp[i]*einheit);
g.setColor(Color.BLACK);
g.drawString(Integer.toString(yp[i]),x0+i*a+14,y0-10);
}
}
}
else{//pruefe
int richtig=0;
for(int i=0;i<anzahl;i++)
{
if(i%5!=4){
g.setColor(Mycolor[i%5]);
if(yp[i]==Zahl[i]){
g.fillRect(x0+i*a+30,y0-Zahl[i]*einheit,b,Zahl[i]*einheit);
}else if(kreuz==false){
g.fillRect(x0+i*a+30,y0-yp[i]*einheit,b,yp[i]*einheit);
int x1=x0+5*a*(i/5)+80;int y1=y0-yl;
int x2=x1+10;int y2=y1;
int x3=x2+30;int y3=y1+50;
int x4=x3-10;int y4=y3;
int[] xl={x1,x2,x3,x4};int[] yl={y1,y2,y3,y4};
int[] xr={x4,x3,x2,x1};int[] yr={y1,y2,y3,y4};
g.setColor(Color.RED);
g.fillPolygon(xl,yl,4);
g.fillPolygon(xr,yr,4);
richtig=1;
}
g.setColor(Color.BLACK);
//g.drawString(Art[i],x0+i*a+30,y0+30);
g.drawString(Integer.toString(Zahl[i]),x0+i*a+45,y0-10);
}
anweisung="normal";
}
if(richtig==0){
g.setColor(Color.RED);
g.setFont(f);
g.drawString("Perfect!!",500,500);
}else{
g.setColor(Color.RED);
g.drawString("Bei den mit X gekennzeichneten S\uFFFD0Š1ulen ",480,490);
g.drawString(" warst Du nichtaufmerksam genug.",480,510);
g.drawString("Bitte trage die richtige S\uFFFD0Š1ulenh\uFFFD0‹2he ein.",480,530);
}
}
//Pfeil
g.setColor(Color.BLACK);
g.fillPolygon(pfeilx,pfeily,3);
//g.fillRect(200,20,400,50);
//Beschriftung
}
//addMouseListener(this);
}
public void mouseClicked(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
if(y<=balken.y0&&y>=balken.y0-balken.yl+2*balken.einheit)
{
for(int i=0;i<balken.anzahl;i++)
{
if(x<=balken.x0+i*balken.a+balken.b+30&&x>=balken.x0+i*balken.a+30){
balken.yp[i]=((balken.y0-y)/balken.einheit);
}
}
}
repaint();
}
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if(y<=balken.y0&&y>=balken.y0-balken.yl+2*balken.einheit)
{
for(int i=0;i<balken.anzahl;i++)
{
if(x<=balken.x0+i*balken.a+balken.b+30&&x>=balken.x0+i*balken.a+30){
balken.yp[i]=((balken.y0-y)/balken.einheit);
}
}
}
repaint();
}
public void mouseReleased(MouseEvent e) {
System.out.println("released at " + e.getX() + "|" + e.getY());
}
public void mouseEntered(MouseEvent e) {
System.out.println("entered");
}
public void mouseExited(MouseEvent e) {
System.out.println("exited");
}
}