Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Coold0wn« (11.12.2012, 22:11)
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 |
<!DOCTYPE html> <html> <body> <CENTER> <h1>Let's play HyperPong!</h1> <p>Here's the game:</p> <applet code=Main.class width="600" height="600"></CENTER> </body> </html> |
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von »Coold0wn« (11.12.2012, 01:28)
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.applet.Applet;
import java.awt.Graphics;
public class Main extends JFrame implements KeyListener
{
private JFrame MainFrame;
private TimerTask balkenTask, ballTask, spinTask;
private ArrayList<String> pressedKeys;
private int BalkenSpeed, balken1y, balken2y, ballx, bally, ballSpeedx, ballSpeedy, hitCounter, p1points, p2points;
private BufferedImage Balken1, Balken2, Ball;
private ImageIcon BalkenIcon1, BalkenIcon2, BallIcon;
private JLabel BalkenLabel1, BalkenLabel2, BallLabel;
private JLabel textarea1, textarea2, pointWinner;
private boolean spinActive = true;
public static void main( String [] args ) {
new Main(true);
}
public Main(boolean spin)
{
spinActive = spin;
MainFrame = new JFrame("Spiel");
MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MainFrame.getContentPane().setLayout(null);
MainFrame.getContentPane().setBackground(Color.BLACK);
MainFrame.setSize(600, 600);
MainFrame.setResizable(false);
pressedKeys = new ArrayList<String>();
BalkenSpeed = 3;
balken1y = 250;
balken2y = 250;
Balken1 = ImageToBufferedImage("images/Balken");
Balken2 = ImageToBufferedImage("images/Balken");
BalkenIcon1 = new ImageIcon(Balken1);
BalkenIcon2 = new ImageIcon(Balken2);
BalkenLabel1 = new JLabel(BalkenIcon1);
BalkenLabel2 = new JLabel(BalkenIcon2);
BalkenLabel1.setBounds(10,balken1y,10,100);
BalkenLabel2.setBounds(580,balken2y,10,100);
MainFrame.getContentPane().add(BalkenLabel1);
MainFrame.getContentPane().add(BalkenLabel2);
hitCounter = 0;
textarea1 = new JLabel("0");
textarea2 = new JLabel("0");
textarea1.setBounds(10,500,100,100);
textarea2.setBounds(490,500,100,100);
textarea1.setForeground(Color.WHITE);
textarea2.setForeground(Color.WHITE);
textarea1.setHorizontalAlignment( SwingConstants.CENTER);
textarea2.setHorizontalAlignment( SwingConstants.CENTER);
MainFrame.getContentPane().add(textarea1);
MainFrame.getContentPane().add(textarea2);
pointWinner = new JLabel("Start mit SPACE.");
pointWinner.setBounds(100,250,400,200);
pointWinner.setForeground(Color.GREEN);
pointWinner.setHorizontalAlignment(SwingConstants.CENTER);
MainFrame.getContentPane().add(pointWinner);
ballSpeedx = 5;
ballSpeedy = 0;
bally = 300;
ballx = 300;
Ball = ImageToBufferedImage("images/Ball");
BallIcon = new ImageIcon(Ball);
BallLabel = new JLabel(BallIcon);
BallLabel.setBounds(ballx,bally,10,10);
MainFrame.getContentPane().add(BallLabel);
balkenTask = new TimerTask(this, 1);
ballTask = new TimerTask(this, 2);
spinTask = new TimerTask(this, 3);
MainFrame.addKeyListener(this);
MainFrame.setVisible(true);
MainFrame.requestFocus();
}
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.awt.event.*;
import javax.swing.*;
public class TimerTask implements ActionListener
{
private Timer t;
private Main main;
private int ID, speed, spinStaerke;
private String direction = "Zero";
public TimerTask(Main main, int id)
{
this.main = main;
ID = id;
speed = 20;
if(ID == 1)
t = new Timer(20, this);
if(ID == 2)
t = new Timer(20, this);
if(ID == 3)
t = new Timer(200, this);
}
|

|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
public class MyApplet extends JApplet {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try { SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
MyTopJPanel panel;
panel.setOpaque(true);
setContentPane(panel);
}});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import javax.swing.*;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
public class MyApplet extends JApplet {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try { SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JPanel panel = new JPanel();
panel.setOpaque(true);
setContentPane(panel);
}});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
|

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Coold0wn« (11.12.2012, 02:49)
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 |
<!DOCTYPE html> <html> <body> <CENTER> <h1>Let's play HyperPong!</h1> <p>Here's the game:</p> <applet code=MyApplet.class width="600" height="600"> </CENTER> </body> </html> |
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import javax.swing.*;
import javax.swing.JApplet;
public class MyApplet extends JApplet {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try { SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
Main panel = new Main();
panel.setOpaque(true);
setContentPane(panel);
}});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
public class Main extends JPanel implements KeyListener
{
private TimerTask balkenTask, ballTask, spinTask;
private ArrayList<String> pressedKeys;
private int BalkenSpeed, balken1y, balken2y, ballx, bally, ballSpeedx, ballSpeedy, hitCounter, p1points, p2points;
private BufferedImage Balken1, Balken2, Ball;
private ImageIcon BalkenIcon1, BalkenIcon2, BallIcon;
private JLabel BalkenLabel1, BalkenLabel2, BallLabel;
private JLabel textarea1, textarea2, pointWinner;
private boolean spinActive = true;
public static void main( String [] args ) {
new Main();
}
public Main()
{
this.setLayout(null);
this.setBackground(Color.BLACK);
pressedKeys = new ArrayList<String>();
BalkenSpeed = 3;
balken1y = 250;
balken2y = 250;
Balken1 = ImageToBufferedImage("images/Balken");
Balken2 = ImageToBufferedImage("images/Balken");
BalkenIcon1 = new ImageIcon(Balken1);
BalkenIcon2 = new ImageIcon(Balken2);
BalkenLabel1 = new JLabel(BalkenIcon1);
BalkenLabel2 = new JLabel(BalkenIcon2);
BalkenLabel1.setBounds(10,balken1y,10,100);
BalkenLabel2.setBounds(580,balken2y,10,100);
this.add(BalkenLabel1);
this.add(BalkenLabel2);
hitCounter = 0;
textarea1 = new JLabel("0");
textarea2 = new JLabel("0");
textarea1.setBounds(10,500,100,100);
textarea2.setBounds(490,500,100,100);
textarea1.setForeground(Color.WHITE);
textarea2.setForeground(Color.WHITE);
textarea1.setHorizontalAlignment( SwingConstants.CENTER);
textarea2.setHorizontalAlignment( SwingConstants.CENTER);
this.add(textarea1);
this.add(textarea2);
pointWinner = new JLabel("Start mit SPACE.");
pointWinner.setBounds(100,250,400,200);
pointWinner.setForeground(Color.GREEN);
pointWinner.setHorizontalAlignment(SwingConstants.CENTER);
this.add(pointWinner);
ballSpeedx = 5;
ballSpeedy = 0;
bally = 300;
ballx = 300;
Ball = ImageToBufferedImage("images/Ball");
BallIcon = new ImageIcon(Ball);
BallLabel = new JLabel(BallIcon);
BallLabel.setBounds(ballx,bally,10,10);
this.add(BallLabel);
balkenTask = new TimerTask(this, 1);
ballTask = new TimerTask(this, 2);
spinTask = new TimerTask(this, 3);
this.addKeyListener(this);
this.requestFocus();
}
|
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Coold0wn« (11.12.2012, 03:07)

Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von »Coold0wn« (11.12.2012, 03:58)
jetz kann ich mit dem applet viewer zumindest schonmal zocken.
Zitat
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file automatically generated by BlueJ Java Development -->
<!-- Environment. It is regenerated automatically each time the -->
<!-- applet is run. Any manual changes made to file will be lost -->
<!-- when the applet is next run inside BlueJ. Save into a -->
<!-- directory outside of the package directory if you want to -->
<!-- preserve this file. -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MyApplet Applet</title>
</head>
<body>
<h1>MyApplet Applet</h1>
<hr>
<applet code="MyApplet.class"
width=600
height=600
codebase="."
archive="file:/C:/Program%20Files/BlueJ/lib/bluejcore.jar,file:/C:/Program%20Files/BlueJ/lib/junit-4.8.2.jar,file:/C:/Users/Julian/Desktop/Pong%20Applet/"
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason."
>
Your browser is ignoring the <APPLET> tag!
</applet>
<hr>
</body>
</html>
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Coold0wn« (11.12.2012, 05:20)
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »myabba|schoki« (11.12.2012, 18:22)
ich hätte in 3 jahren nich gepackt ohne dich, danke 


Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Coold0wn« (11.12.2012, 20:17)
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file automatically generated by BlueJ Java Development -->
<!-- Environment. It is regenerated automatically each time the -->
<!-- applet is run. Any manual changes made to file will be lost -->
<!-- when the applet is next run inside BlueJ. Save into a -->
<!-- directory outside of the package directory if you want to -->
<!-- preserve this file. -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MyApplet Applet</title>
</head>
<body>
<h1>MyApplet Applet</h1>
<hr>
<applet code="MyApplet.class"
width=600
height=600
codebase="."
archive="file:/C:/Program%20Files/BlueJ/lib/bluejcore.jar,file:/C:/Program%20Files/BlueJ/lib/junit-4.8.2.jar,file:/C:/Users/Julian/Desktop/Pong%20Applet/"
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason."
>
Your browser is ignoring the <APPLET> tag!
</applet>
<hr>
</body>
</html>
|
