Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Embedding Applet frame on current window?

843807Aug 16 2005 — edited Aug 17 2005
I am trying to get my frame to be embedded in the window that I open, but it pops open an other window. I wanted to know how I could get the frame to "stick to the page without popping the frame up the frame separately?

This is the java code

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;

/********************************************************************
**************New Tape Calculator with drop downs********************
This program will calculate the total number of tapes
that will need to be ordered based on the amount of space needed
********************************************************************/

public class tapeCalc2 extends JFrame implements ActionListener, ItemListener
{
private JTextField spaceField;
private JTextArea resultArea;
private JComboBox osBox;
String operatingSys[] = {"", "Windows", "UNIX"};
private JLabel osLabel, spaceLabel;
private JButton submit;
double fTape_order;


public tapeCalc2()
{
Container con = getContentPane();
con.setLayout(null);

osLabel = new JLabel("Operating System: ");
osBox = new JComboBox(operatingSys);
spaceLabel = new JLabel("Space needed: ");
spaceField = new JTextField(25);
submit = new JButton("Submit");
resultArea = new JTextArea(30, 50);

spaceLabel.setBounds(20, 30, 90, 65);
spaceField.setBounds(115, 45, 105, 25);
osLabel.setBounds(20, 70, 125, 45);
osBox.setBounds(135, 75, 100, 25);
submit.setBounds(155, 105, 90, 40);
resultArea.setBounds(20, 160, 250, 300);

con.add(spaceLabel);
con.add(spaceField);
con.add(osLabel);
con.add(osBox);
con.add(submit);
con.add(resultArea);

osBox.addItemListener(this);
submit.addActionListener(this);

setSize(600, 600);
setVisible(true);
}


public void itemStateChanged(ItemEvent event)
{
int spaceGB = Integer.parseInt(spaceField.getText());
int fulls = 5, monthly = 12, years = 2,
fFulls, fMonthly, fYears;
double incrementals = .3333, fIncrementals,
total, total_tapes, spare_tapes, tape_order;


// if(osBox.getSelectedItem().equals("Windows"))
if(osBox.getSelectedIndex() == 1)
{
//System.out.println("\n\nYou are requesting tapes for Windows");
resultArea.setText("\n\nYou are requesting tapes for Windows\n\n");
fFulls = fulls * spaceGB;
fMonthly = monthly * spaceGB;
fYears = years * spaceGB;
fIncrementals = incrementals * fFulls;

resultArea.append("Fulls: " + fulls + "\nMonthly: " + monthly +
"\nYears: " + years + "\nIncrementals: " + incrementals + "\n\n\n");
/* System.out.println("Fulls: " + fulls + "\nMonthly: " + monthly +
"\nYears: " + years + "\nIncrementals: " + incrementals + "\n\n\n");*/

total = fFulls + fMonthly + fYears + fIncrementals;
total_tapes = total / 300;
spare_tapes = total_tapes * 0.1;
tape_order = total_tapes + spare_tapes;
fTape_order = Math.ceil(tape_order);

}

// else if(osBox.getSelectedItem().equals("UNIX"))
else if(osBox.getSelectedIndex() == 2)
{
//System.out.println("\n\nYou are requesting tapes for UNIX\n\n");
resultArea.setText("\n\nYou are requesting tapes for UNIX\n\n");
fFulls = fulls * spaceGB;
fIncrementals = incrementals * fFulls;

//System.out.println("Fulls: " + fulls + "\nIncrementals: " + incrementals + "\n\n\n");
resultArea.append("Fulls: " + fulls + "\nIncrementals: " + incrementals + "\n\n\n");

total = fFulls + fIncrementals;
total_tapes = total / 300;
spare_tapes = total_tapes * 0.1;
tape_order = total_tapes + spare_tapes;
fTape_order = Math.ceil(tape_order);

}

}//end of ItemStateChanged

public void actionPerformed(ActionEvent action)
{
resultArea.append(fTape_order + " Total tapes to be ordered\n");
//System.out.println(fTape_order + " Total tapes to be ordered\n");
resultArea.append("Thank You! Your order has been submitted!");
//System.out.println("Thank You! Your order has been submitted!");
}

public static void main(String arg[])
{
tapeCalc2 tape = new tapeCalc2();
}
}


This is the html code that should embed the applet

<html>
<head>
<title>Practice Applet</title>
<head>
<body>
<APPLET CODE="tapeCalc2.class" WIDTH="400" HEIGHT="200"></APPLET>
</body>
</html>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 14 2005
Added on Aug 16 2005
2 comments
157 views