I'm having problems figuring where I need to go next in this project to create an applet from this application... any suggestions where I should start (in layman's terms)?

import javax.swing.*;

public class storageSP {

	public static void main(String[] args) {
		//declare variables
		float res;
		String kfilm;
		String sfps;
		float fps;
		String sminutes;
		String sseconds;
		float minutes;
		float seconds;
		float minsec;
		float Bit;
		float Byte;
		float kbyte;
		float mbyte;
		float gbyte;
		float tbyte;
		//int pbyte; if needed in the future
		Object size;
		float storage;
		double perc50;
		int ultStorage;

		
		//#get k of film
		kfilm = JOptionPane.showInputDialog("Please enter film type 1k,2k, 4k, or 8k? ");
		
	    if (kfilm.equals("1k")){
	    	res = 1024*778;//796672
	    }
	    else if (kfilm.equals("2k")){
	    	res = 2048*1556;//3186688
	    }
	    else if (kfilm.equals("4k")){
	    	res = 4096*3112;//12746752
	    }
	    else if (kfilm.equals("8k")){
	    	res = 8192*6224;//50987008
	    }
	    else {
	    	return;
	    }
	    
		//get fps
		sfps = JOptionPane.showInputDialog("How many frames/second? 30 (COMMON - mono), 60 (stereo), or 24 (film)  ");
		fps = Integer.parseInt(sfps.trim());
		
		//How long?
		sminutes = JOptionPane.showInputDialog("How many minutes? ");
		sseconds = JOptionPane.showInputDialog("How many seconds? ");
		minutes = Integer.parseInt(sminutes.trim());
		seconds = Integer.parseInt(sseconds.trim());
		
		if (minutes >0){
			minsec = minutes*60;
			minsec = minsec+seconds;
		}
		else {
		    minsec = seconds;
		}	
		
		//# Measurement in Bits, Bytes...etc
		Bit=res*4*fps*minsec;//resolution*4channels*fps*minutes and seconds
		Byte = Bit/8;
		kbyte = Byte/1024;
		mbyte = kbyte/1024;
		gbyte = mbyte/1024;
		tbyte = gbyte/1024;
		
		//# figure the bits, bytes, kbytes, mbytes, gbytes, tbytes, or pbytes needed
		if (Bit < 1024){
			size = "Bit";
			storage = Bit;
		}
		else if (Byte < 1024){
			size = "Byte";
			storage = Byte;
		}
		else if (kbyte < 1024){
			size = "kB";
			storage = kbyte;
		}
		else if (mbyte < 1024){
			size = "MB";
			storage = mbyte;
		}
		else if (gbyte < 1024){
			size = "GB";
			storage = gbyte;
		}
		else if (tbyte < 1024){
			size = "TB";
		    storage = tbyte;
		}
		else{
			return;
		}
			
		perc50 = storage * .50;//50 percent of storage
		ultStorage = (int) (storage+perc50);
		//#need to ensure proper storage space
		JOptionPane.showMessageDialog(null,"Size of project is: "+storage+" "+size+
				"\nTherefore, you'll need "+ultStorage+" "+size+" of space.");
	}
}

Recommended Answers

All 8 Replies

First read the API doc on applets and the Tutorial about Applets
Start with a class that extends JApplet.
Move the code in main() to an init() method.

Okay, I've tried to research on how to convert apps to applets and it's still not making sense. Here is what I did, but this still won't run in the applet.

import java.applet.Applet;
import java.util.*;
import java.awt.*;
import javax.swing.*;


public class storageApplet extends JApplet {
	public void init(){//declare variables
		float res;
		String kfilm;
		String sfps;
		float fps;
		String sminutes;
		String sseconds;
		float minutes;
		float seconds;
		float minsec;
		float Bit;
		float Byte;
		float kbyte;
		float mbyte;
		float gbyte;
		float tbyte;
		//int pbyte; if needed in the future
		Object size = null;
		float storage;
		double perc50;
		int ultStorage;	
	
		//#get k of film
		kfilm = JOptionPane.showInputDialog("Please enter film type 1k,2k, 4k, or 8k? ");
		
	    if (kfilm.equals("1k")){
	    	res = 1024*778;//796672
	    }
	    else if (kfilm.equals("2k")){
	    	res = 2048*1556;//3186688
	    }
	    else if (kfilm.equals("4k")){
	    	res = 4096*3112;//12746752
	    }
	    else if (kfilm.equals("8k")){
	    	res = 8192*6224;//50987008
	    }
	    else {
	    	return;
		}
	  //get fps
		sfps = JOptionPane.showInputDialog("How many frames/second? 30 (COMMON - mono), 60 (stereo), or 24 (film)  ");
		fps = Integer.parseInt(sfps.trim());
		
		//How long?
		sminutes = JOptionPane.showInputDialog("How many minutes? ");
		sseconds = JOptionPane.showInputDialog("How many seconds? ");
		minutes = Integer.parseInt(sminutes.trim());
		seconds = Integer.parseInt(sseconds.trim());
		
		if (minutes >0){
			minsec = minutes*60;
			minsec = minsec+seconds;
		}
		else {
		    minsec = seconds;
		}	
		
		//# Measurement in Bits, Bytes...etc
		Bit=res*4*fps*minsec;//resolution*4channels*fps*minutes and seconds
		Byte = Bit/8;
		kbyte = Byte/1024;
		mbyte = kbyte/1024;
		gbyte = mbyte/1024;
		tbyte = gbyte/1024;
		
		//# figure the bits, bytes, kbytes, mbytes, gbytes, tbytes, or pbytes needed
		if (Bit < 1024){
			storage = Bit;
			size = "Bits";
		}
		else if (Byte < 1024){
			storage = Byte;
			size = "Bytes";
		}
		else if (kbyte < 1024){
			storage = kbyte;
			size = "kB";
		}
		else if (mbyte < 1024){
			storage = mbyte;
			size = "MB";
		}
		else if (gbyte < 1024){
			storage = gbyte;
			size = "GB";
		}
		else if (tbyte < 1024){
		    storage = tbyte;
		    size = "TB";
		}
		else{
			return;
		}
		
		perc50 = storage * .50;//50 percent of storage
		ultStorage = (int) (storage+perc50);
		
		JOptionPane.showMessageDialog(null, "The project takes up:  " + storage + size + "\nTherefore, you'll need:  " + ultStorage + size + " of space.");
		//#need to ensure proper storage space
	}
}

do this

public void init()
{
write all here
}

Thats all you nothing else

Please do not forget to extend JApplet for th class

but this still won't run in the applet.

Can you explain please?

This won't run in the applet, even thought the applet is open. The code still runs in the JOption Pane... not the applet. Please test this out if needed. If I'm needing another plugin for Eclipse, please let me know so this runs properly.

Thanks!

This won't run in the applet, even thought the applet is open. The code still runs in the JOption Pane

What is the code supposed to do?
What does "run" mean? Does the code execute? Does it do what you've coded it to do?
It looks like it uses some JOptionPanes to ask a question and display a result.

so this runs properly

What does "properly" mean?

I think you need to read up on GUI programming if you want to change the code.

I'm not sure the correct java terminology (I'm assuming that's what you need from me). But, I need the output (questions for user and response from user) to show up INSIDE the applet. I've tried researching under API's, GUI sites, along with other sites, but I'm still not finding the answer.

If you want [NORMR1], you can help me correct my java terminology so I can form better questions that can be understood by other programmers. That way, the thread communication between us and others will be improved. Otherwise, I have no idea what or how I can request assistance on this project.
Thank you!

The basic things to consider when moving an application to an applet is to have all the components that are added to the JFrame's contentPane be added to the JApplet which extends Pane or to a JPanel which is added to the applet.
The other things to consider is where to put initialization code. Applets have several methods that are called by the browser. It does NOT call a main() method.
You can do some things in the constructor, but most should be done in the init() method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.