Konular

Applet, Konsol Uygulaması veya Masa Üstü Uygulaması NetBeans'ta nasıl çalışır

ingilizce bir makale

Creating or Importing an Applet Source File

In this section, you create your first applet. Possibly, you already have an applet and, in this case, you can use the instructions below to import it into the IDE.

Create the Java project from scratch or from existing sources

  1. Choose File > New Project (Ctrl-Shift-N). Under Categories, select Java.
  2. Choose one of the following:
    • If you are creating a new applet source file, select Java Class Library under Projects. Click Next.
    • If you want to import an applet source file, select Java Project with Existing Sources. Click Next. Specify the file's location in the Source Packages Folder text box.
  3. Under Project Name, type HelloApplet. Change the Project Location to any folder on your computer.
  4. Click Finish. If you imported an applet source file, run it.

Create the applet source file

  1. Right-click the HelloApplet project node in the Projects window and select New > Other (Ctrl-N).
  2. Under Categories, select Java. Under File Types, select Applet.

    Alternatively, if you want to visually design your applet, select Swing GUI Forms > JApplet Form.

    Click Next.

  3. Under Class Name, type MyApplet. Under Package, type org.me.hello.
  4. Click Finish.

    The IDE creates the applet source file in the specified package. The applet source file opens in the Source editor.
  5. Define your applet class by copying and pasting the following code over the existing default code:
         package org.me.hello;
    
         import java.applet.Applet;
         import java.awt.Graphics;
    
         public class MyApplet extends Applet {
             public void paint(Graphics g) {
                 g.drawString("Hello applet!", 50, 25);
             }
         }
    
                        

    Alternatively, if you are designing an Applet Form instead, use the Designing a Swing GUI in NetBeans IDE document to create something like the following:

    Applet Form design

    For detailed information on writing applets, see The JavaTM Tutorial's Applets section.

 

Running an Applet Source File

The applet that you created can be run from the IDE. This section shows you how to do so.

Build and run the applet source file

  1. Right-click the HelloApplet project node in the Projects window and choose Build from the contextual menu.
  2. The HelloApplet.jar file is created in the dist folder, which you can see if you switch to the Files window (Ctrl-2).
  3. Right-click the applet class node (i.e., right-click "MyApplet.java" not the "HelloApplet" project) in the Projects window and choose Run File from the contextual menu.

    The MyApplet.html launcher file, with the applet embedded, is created in the build folder, which you can see if you switch to the Files window (Ctrl-2):

    View applet

    The applet is launched in the Applet Viewer:

    View applet

    Applet forms are also displayed in the Applet Viewer:

    design


 

Embedding an Applet in a Web Application

Your applet is complete. Now you need to make it available to the user. To do so, you create a web application, put the applet JAR on its classpath, and then add an applet tag to the web application's HTML file.

Create the web project

  1. Choose File > New Project. Under Categories, select Web. Under Projects, select Web Application. Click Next.
  2. Under Project Name, type HelloWebApplet. Change the Project Location to any folder on your computer. Click Next, select your server, and click Finish.

Add the applet JAR file to the web project

When you want to include an applet JAR file in a web project, you can do so by adding the Java project that contains the JAR file, or by adding the JAR file itself. Although the choice is yours, note that when you add the Java project to the web project, you enable the IDE to build the applet whenever you build the web application. Therefore, when you modify the applet in the Java project, the IDE builds a new version of the applet whenever the web project is built. On the other hand, if the applet JAR file is not in a NetBeans IDE project, the applet source file is not rebuilt when you build the web project.

  1. In the Projects window, right-click the HelloWebApplet project node and select Properties from the contextual menu.
  2. Choose one of the following:
    • If the applet JAR file is in a Java project, click Packaging, and then click Add Project. Browse to and select the folder that contains the Java project. Note that IDE projects are marked by the NetBeans IDE project icon.
    • If the applet JAR file is not in a IDE project, click Packaging, and then click Add JAR/Folder. Browse to and select the folder that contains the JAR file.
  3. The JAR file containing the applet source file is listed in a table at the bottom of the Project Properties dialog box.

  4. Optionally, you can type a location for the applet in the table's Path in WAR column. By default, the applet JAR file will be copied to the web application's document root, which is the build/web folder (the highest level of the web application's file structure). Click OK.

    When you build the project, the applet's JAR file is packaged in the project's WAR file in the dist folder. It is also added to the build/web folder. For details, see the illustration below.

    View applet

Create and run the JSP file or HTML file

  1. Choose one of the following:
    • If you want to embed the applet in a JSP file, double-click the default index.jsp file in the Projects window. This file is created by the IDE when you create a web project. It opens in the Source Editor.
    • If you want to embed the applet in an HTML file, right-click the HelloWebApplet project node, and choose New > Other from the contextual menu. Under Categories, select Web. Under File Types, select HTML. Click Next. Give your HTML file a name and click Finish.
  2. Embed the applet in the file by adding the following applet tag anywhere between the file's <body></body> tags:
    <applet code="org.me.hello.MyApplet" archive="HelloApplet.jar"/> 
    • org.me.hello.MyApplet is the full classname to your applet
    • HelloApplet.jar is the JAR file that contains the applet
  3. Right-click the JSP node or HTML node in the Projects window and choose Run File from the contextual menu.

    The server deploys the JSP file or HTML file in the IDE's default browser.

    You should see something similar to the illustration below:

    View applet

    For applet forms, you should see something similar to the following:

    design

Kaynak www.netbeans.org/kb/61/web/applets.html

Yorumunuzu Ekleyin

Java Applet Nedir?

Applet örnekleri,applet ve japplet farkı

46,523 Okunma 4 Yorum 05/03/2010 09:49:53

Java Applet Nedir?

Java applet nedir?apllet Örnekleri,applet ve japplet farkı

28,992 Okunma 1 Yorum 11/03/2010 08:59:42

Java Applet Layout Kullanımları

setLayout(null); setLayout(new FlowLayout()); setLayout(new BorderLayout()); new CardLayout(); Yerleşim Yöneticileri

27,573 Okunma 1 Yorum 26/01/2010 00:09:26 12/04/2017 00:12:53

Connecting to a MySQL Database

This document demonstrates how to set up a connection to a MySQL database from NetBeans IDE 6.1. Once connected, you can begin working with MySQL in the IDE's Database Explorer by creating new databases and tables, populating tables with data, and running SQL queries on database structures and content. This tutorial is designed for beginners with a basic understanding of database management, who want to apply their knowledge to working with MySQL in NetBeans IDE.

25,731 Okunma Henüz yorum yapılmamış 16/10/2008 18:48:41

Applet Nedir?

Appletlerin temel özellikleri ve kısıtlamalarının aşılması

24,204 Okunma Henüz yorum yapılmamış 03/01/2009 05:42:13

Java Aplleti imzalamak (Signed applet)

Security manager adlı sistemi sayesinde koda bazı sınırlamalar koyarak kullanıcıya zarar vermesi önlenir. Appletlerdeki bu sınırlamayı aşmanın tek yolu signed applet yaratmaktır

23,878 Okunma Henüz yorum yapılmamış 03/07/2010 17:36:51

Kullanıcının Bilgisayarında İşlem Yapmaya Yetkili Güvenilir (Signed) Applet Yazmak

Applet kodlarınız kendi makinenizde sorunsuzca çalışıyor ancak webe attığınızda çalışmıyorsa sebebi appletlerin güvenlik sınırlamalarıdır. Bunu aşmak için appleti imzalamalısınız ve kullanıcılarda appletin bilgisayarlarında yapabileceklerini kabul ettiklerinde ancak applet çalışacaktır. Buna Yerel Dosya Sistemine Erişmeye Yetkili Güvenilir Applet yazmakta denebilir.

23,280 Okunma 1 Yorum 04/07/2010 16:19:54

Java İlk Kodlar (jcreator)

Java classpath tanımlamaları, consolda ilk program yazılması, derlenmesi, çalıştırılması aynı uygulamanın netbeansta yapılışı ve class, java ve jar dosyalarının gösterilmesi

22,345 Okunma Henüz yorum yapılmamış 27/10/2008 14:22:54

Java Applet JFileChooser

Java swing arayüzlerinden - dosya sistemine erişimi sağlayan JFileChooser sınıfının detayları

21,052 Okunma Henüz yorum yapılmamış 19/07/2010 23:39:20

Dosya Gezinti Peceresi Açmak

NetBeans IDE'si ile bir dosya açma penceresi açarak dosya sisteminde gezinti yapan ve sonuçta seçilen dosyayı ekrana yazıp, kaç karakterden oluştuğunu veren bir uygulama.

18,588 Okunma Henüz yorum yapılmamış 07/11/2008 10:41:35

Yükleniyor...