Апплет java intellij idea

Как запустить апплет в Intellij IDEA?

Я пытаюсь запустить эти апплеты для своего сетевого курса. Когда я попытался запустить их в браузере из ссылок, они ничего не сделали. Поэтому я решил попробовать и скомпилировать их в IntelliJ, но когда я запускал код, он ничего не делал. Сообщения об ошибках не возвращаются. Единственное, что я сделал, чтобы изменить код из исходного кода, это добавить основной метод и удалить объявление пакета. Ниже приведен апплет, который я пытался запустить:

Код JAVA

/////////////////////////////////////// //LineSimApllet //written by David Grangier, Institut Eurecom, France //[email protected] /////////////////////////////////////// //imports import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.applet.*; import java.util.*; //Applet Class public class LineSimApplet extends Applet < //buttons Button start = new Button("Start"); Button stop = new Button("Reset"); //features lists MyChoice length = new MyChoice(new String[], new double[], 3); MyChoice rate = new MyChoice(new String[], new double[], 2); MyChoice size = new MyChoice(new String[], new double[], 1); //to simulate time Thread timerThread; TickTask timerTask; boolean simulationRunning = false; //communication line Line myLine; public void init() < try < setBackground(Color.white); add(new Label("Length", Label.RIGHT)); add(length); add(new Label("Rate", Label.RIGHT)); add(rate); add(new Label("Packet size", Label.RIGHT)); add(size); //start start.addActionListener( new ActionListener() < public void actionPerformed(ActionEvent event) < launchSim(); >>); add(start); //stop Button stop = new Button("Reset"); stop.addActionListener( new ActionListener() < public void actionPerformed(ActionEvent event) < stopSim(); //clear line myLine.sendTime(0); //redraw cleared line LineSimApplet.this.repaint(); >>); add(stop); //line myLine = new Line(40, 50, 450, 10); > catch (Exception e) < e.printStackTrace(); >> public void paint(Graphics g) < update(g); // eliminate flashing : update is overriden >public void update(Graphics g) < //work on a offscreen image Dimension offDimension = getSize(); Image offImage = createImage(offDimension.width, offDimension.height); Graphics offGraphics = offImage.getGraphics(); myLine.drawLine(offGraphics); //sender offGraphics.setColor(Color.blue); offGraphics.fillRect(10, 40, 30, 30); offGraphics.setColor(Color.black); offGraphics.drawString("Sender", 5, 90); offGraphics.drawRect(10, 40, 30, 30); //receiver offGraphics.setColor(Color.blue); offGraphics.fillRect(490, 40, 30, 30); offGraphics.setColor(Color.black); offGraphics.drawString("Receiver", 485, 90); offGraphics.drawRect(490, 40, 30, 30); offGraphics.drawString("Propagation speed : 2.8 x 10^8 m/sec", 175, 105); //display offscreen image g.drawImage(offImage, 0, 0, this); >private void launchSim() < setupEnabled(false); //setup line myLine.setup(length.getVal(), rate.getVal()); myLine.emitPacket(size.getVal(), 0); //setup timer timerTask = new TickTask(1E-5, myLine.totalTime()); timerThread = new Thread(timerTask); //start simulation simulationRunning = true; timerThread.start(); >private void stopSim() < timerTask.endNow(); simulationRunning = false; setupEnabled(true); >public void setupEnabled(boolean value) < start.setEnabled(value); length.setEnabled(value); rate.setEnabled(value); size.setEnabled(value); >//my choice class MyChoice extends Choice < private double vals[]; public MyChoice(String items[], double values[], int defaultValue) < for (int i = 0; i < items.length; i++) < super.addItem(items[i]); >vals = values; select(defaultValue - 1); > public double getVal() < return vals[super.getSelectedIndex()]; >> //tickTask class TickTask implements Runnable < private double counter; private double length; private double tick; public TickTask(double t, double l) < length = l; tick = t; counter = 0; >public void run() < while (LineSimApplet.this.simulationRunning) < counter += tick; LineSimApplet.this.myLine.sendTime(counter); LineSimApplet.this.repaint(); if (counter >= length) < LineSimApplet.this.myLine.clearPackets(); LineSimApplet.this.timerThread.suspend(); >try < LineSimApplet.this.timerThread.sleep(50); >catch (Exception e) < >> > public void endNow() < length = counter; >> > //Line class class Line < //graphic variables private int gX; private int gY; private int gWidth; private int gHeight; //characteristic variables final double celerity = 2.8E+8; private double length; private double rate; //simulation variables private double time; private Packet myPacket; public Line(int x, int y, int w, int h) < //graphic init gX = x; gY = y; gWidth = w; gHeight = h; >public void setup(double l, double r) < length = l; rate = r; >void sendTime(double now) < time = now; //update time removeReceivedPackets(now); >void emitPacket(double s, double eT) < myPacket = new Packet(s, eT); >private void removeReceivedPackets(double now) < if (!(myPacket == null)) < if (now >myPacket.emissionTime + (myPacket.size / rate) + length * celerity) < clearPackets(); >> > public void clearPackets() < myPacket = null; >public double totalTime() < double emmissionTime = (myPacket.size / rate); double onLineTime = (length / celerity); return (emmissionTime + onLineTime); >public void drawLine(Graphics g) < g.setColor(Color.white); g.fillRect(gX, gY + 1, gWidth, gHeight - 2); g.setColor(Color.black); g.drawRect(gX, gY, gWidth, gHeight); g.setColor(Color.red); g.drawString(timeToString(time), gX + gWidth / 2 - 10, gY + gHeight + 15); drawPackets(g); >private void drawPackets(Graphics g) < if (!(myPacket == null)) < double xfirst; double xlast; //compute time units xfirst = time - myPacket.emissionTime; xlast = xfirst - (myPacket.size / rate); //compute position xfirst = xfirst * celerity * gWidth / length; xlast = xlast * celerity * gWidth / length; if (xlast < 0) < xlast = 0; >if (xfirst > gWidth) < xfirst = gWidth; >//draw g.setColor(Color.red); g.fillRect(gX + (int) (xlast), gY + 1, (int) (xfirst - xlast), gHeight - 2); > > static private String timeToString(double now) < String res = Double.toString(now * 1000); int dot = res.indexOf('.'); String deci = res.substring(dot + 1) + "000"; deci = deci.substring(0, 3); String inte = res.substring(0, dot); return inte + "." + deci + " ms"; >public static void main(String[] args) < LineSimApplet ls = new LineSimApplet(); ls.init(); >> class Packet < double size; double emissionTime; Packet(double s, double eT) < size = s; emissionTime = eT; >> 

Источник

Читайте также:  How to insert images in css

My Studying of Java

If you want create a new applet using awt library via IntelliJ IDEA then you will need to take several simple steps.

1. Start IntelliJ IDEA and create new project:

Press «Next» button
4. Write name you project, and other by default

import java.applet.*; import java.awt.*; /** * Created by Aleksandr on 14.03.2017. */ public class AppletClass extends Applet< public void init() < >public void start() < >public void stop() < >public void destroy() < >public void paint (Graphics g) < >>

7.Tell IntelliJ Idea you want to make an applet by right-clicking on the new class you created and selecting «Create ‘className'»

8. Make sure that «Applet class» is selected, you’ll be able to chose it’s height and width
«Applet Parameters» section allows you to enter/set up parameters that will be accessible via .getParameter(«newParameter»);

Источник

Апплет java intellij idea

Configure the configuration after building the project

Add -Dfile.encoding=GBK in the VM options for appletviewer column

The directory structure is as follows

game.html

myGame.java

displayed after running

Trying to compile myGame.java is still useless

Here, by the way, how to compile myGame.java

cmd into the src folder, execute the command javac myGame.java to generate the myGame.class file in the same folder

If prompted that javac is not an external or internal command, press the article to set

Back to the topic java applet

According to the following article step by step, you can open the applet program box in cmd, but it cannot be opened in the browser.Java plugin for chrome not found, This problem needs to be solved

Prompt when using appletviewer in cmd, warning: Cannot read the property file of AppletViewer: C:\Users\Administrator.hotjava\properties

Follow the article below to solve the problem

Can’t find the main class in IDEA, Study it again, at least the applet can now run normally

Источник

Апплет java intellij idea

Japlis Applet Runner with IntelliJ screenshot

Japlis Applet Runner with Eclipse screenshot

Japlis Applet Runner with NetBeans screenshot

Features

  • History (last 10 URLs)
  • Bookmarks
  • Clear history
  • Clear cache
  • Applet from HTML file
  • Applet from JavaScript file (deployApplet.js)
  • Applet from JNLP file
  • Applet from a Jar file if the Main-Class extends (J)Applet
  • Applet from a class file if the class has no package and extends (J)Applet
  • Applet from internet (https) (http pro version only)
    Note that the first start might be slower as files are downloaded and verified by your antivirus application if you have one installed.
  • Applet from local file system or shared directory
  • Office
    • PDF Viewer
    • Microsoft Word Viewer (docx)
    • Excel & CSV Viewer (xlsx, xls, cvs)
    • Powerpoint Viewer (pptx)
    • MP3 Player (mp3, ogg)
    • Video Player (mp4, mkv, mp3, avi, . )
    • Clipboard History (More features when running in Applet Runner Pro)
    • JSON Viewer
    • XML Viewer
    • YAML Viewer
    • Encoding / Decoding: URL, Base64, XML, Query parameters, Hex, Hexadecimal numbers, Binary numbers, ROT13, ROT47, Unicode, Morse, Cyrillic, Volapuk
    • Lines: Sort, Reverse, Shuffle, Number, Delete duplicates, Trim spaces, Extract words, Join, Sort by length, Remove empty, Delete 1 out of 2, Count occurrences, Format HTML/XML, Format JSON
    • Pattern: Prefix, Suffix, Keep regular expression (regexp), Remove regexp, Keep lines, Remove lines, Split regexp, Contains regexp, Replace regexp, To lowercase regexp, To uppercase regexp, Date to long, Long to date
    • Text Characteristics: Character count, Word count, Line count, XML validate, Hash code, MD2, MD5, CRC32, Adler32, SHA-1, SHA-256, SHA-384, SHA-512, SHA3-224, SHA3-256, SHA3-384, SHA3-512
    • Properties: Java system properties, Java Swing UI Defaults, Computer environment properties
    • Characters: Character in specified font, Hexadecimal value based on specified character encoding, Decimal value, Character name, Character category
    • Find in files: Find regular expression in specified files, Show file names, Show found line numbers, Show number of occurrence found
    • English, French, Spanish, Dutch, German, Italian, Hebrew, Portuguese, Swedish, Danish, Norwegian, Hungarian, Russian, Latin and Czech
    • World countries, Elements Table, Morse Code and NATO alphabet, United States, Départements français, English/German/Dutch Irregular Verbs.
    • Clock, Calendar, Alarm clock, Stopwatch, Timer, Server clock, Time Zones, Countdown until Date, Pomodoro / HIIT
    • Windows
    • Mac OS X
    • Linux
    • IntelliJ Platform Based Products like
      • Android Studio
      • IntelliJ IDEA community/ultimate/education edition
      • PyCharm community/professional/education edition
      • WebStorm
      • PhpStorm
      • Rider
      • Hide toolbar and only start with a specific applet
      • You can redistribute the plugin inside your company
      • Customized toolbar: own bookmarks, own buttons, remove text field
      • Security: only allow a domain or subdomain
      • Run as standalone application for Windows, Mac OS X and Linux
      • Override Applet start-up parameters with url query parameters
      • Possibility to use system properties or environment properties in the applet parameters
      • Documentation
      • You want to run multiple software in your company IDE’s. You don’t want to write/package/deploy 3 plug-ins per software
      • Each time you update one of your software, you don’t want to repackage/redeploy 3 plug-ins or applications.
      • Multiple IDE’s are used in your company and you want to provide an IDE independent small tool.
      • You don’t want to learn the complexity to create/package/distribute/maintain a plug-in for each IDE.
      • Why Applet and not JPanel?
        Applet has lifecycle, JApplet implements RootPaneContainer, JApplet can have a menu, it accepts parameters and there are standards (html, jnlp) to specify Applet class, classpath and parameters.
      • Examples of applets you could write and run in this plug-in in just a few lines
        • Copy, edit or delete a file on the file system
        • Run a script like start a docker image when clicking on a button
        • Regularly check the status of different servers and show a red dot when the server down

        Screenshots

        Japplis Applet Runner IntelliJ plug-in Japplis Applet Runner IntelliJ plug-in with Japplis Toolbox applet Japplis Applet Runner Eclipse plug-in Japplis Applet Runner Eclipse plug-in with Japplis Watch applet Japplis Applet Runner NetBeans plug-in Japplis Applet Runner NetBeans plug-in with JLearnIt applet

        Videos




        Productivity

        Источник

Оцените статью