Jag gjorde för ett tag sedan en tråd där jag frågade vart man ska "börja" ifall man vill lära sig lite java(-spel-)programmering.
Jag fick bl.a. länken: http://www.javacooperation.gmxhome.de/TutorialStartEng.html som jag är mycket tacksam för, och har "jobbat" mig igenom det första kapitlet (Har inte orkat eftersom jag har "latat mig" nu under lovet ^^ )
Men så läser jag och hittar att det finns en annan metod, Swing (?), att programmera grafik i java med.
Alltså så finns 2 sorters kodskrivning (grunderna kopierade från den tutorial-hemsidan och från wikipedia)
Applets:
Ett stycke javascript-kod:
// import necessary packages
import java.applet.*;
import java.awt.*;
// Inherit the applet class from the class Applet
public class FirstApplet extends Applet
{
// Now you should implement the following methods
// init - method is called the first time you enter the HTML site with the applet
public void init() {... }
// start - method is called every time you enter the HTML - site with the applet
public void start() {... }
// stop - method is called if you leave the site with the applet
public void stop() {... }
// destroy method is called if you leave the page finally (e. g. closing browser)
public void destroy() {... }
/** paint - method allows you to paint into your applet. This method is called e.g. if you move your browser window or if you call repaint() */
public void paint (Graphics g) { }
}
^ Sedan så läggs allt i en .html fil och körs i webbläsaren
Och så finns då detta Swing som jag upptäckte nu
http://en.wikipedia.org/wiki/Java_Swing#A_basic_example
Ett stycke javascript-kod:
// Import the swing and AWT classes needed
import java.awt.EventQueue;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
/**
* Basic Swing example.
*/
public class SwingExample {
public static void main(String[] args) {
// Make sure all Swing/AWT instantiations and accesses are done on the
// Event Dispatch Thread (EDT)
EventQueue.invokeLater(new Runnable() {
Override
public void run() {
// Create a JFrame, which is a Window with "decorations", i.e.
// title, border and close-button
JFrame f = new JFrame("Swing Example Window");
// Set a simple Layout Manager that arranges the contained
// Components
f.setLayout(new FlowLayout());
// Add some Components
f.add(new JLabel("Hello world!"));
f.add(new JButton("Press me!"));
// "Pack" the window, making it "just big enough".
f.pack();
// Set the default close operation for the window, or else the
// program won't exit when clicking close button
// (The default is HIDE_ON_CLOSE, which just makes the window
// invisible, and thus don't exit the app)
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
// Set the visibility as true, thereby displaying it
f.setVisible(true);
}
});
}
}
Men innan jag googlar jämförelser så undrar jag ifall någon kan göra en simpel jämförelse, ifall en sådan finns, t.ex vad som är bäst till vad och vad som är enklast till vad?
Tackar
///Mattedatten
//M