Beginner needs Java applet Help!!!
I would be greatful if someone could answer any of the questions below following the description, thank you:
Description:
There are 3 textFields, 3buttons(add,delete,display), and 1 textArea on my applet.
User types their "name" in the first textField(called tField1)
User types their "surnname" in the second textField(called tField2)
User Types their "Town" in the Third textField(called tField3)
User presses add button to add details to an array of type "member".
User presses display to view all members(elements of the array) in the TextArea.
User adds details to textFields and presses the delete button to delete that member.
member.class:
Has constructors, individual set and get methods and private attributes name,surname + address plus a toString method.
Code Behind the ADD button i.e. in the VOID ADD_ACTIONTIONPERFORMED(ACTION EVENT) method:
Q1.How do i create an array of type member?
Is it: MEMBER X[] = NEW MEMBER[100]; If so Where does this statement go?
Q2.How do i allow the user to keep adding more members every time the add button is pressed?
Code Behind the DISPLAY button i.e. in the VOID DISPLAY_ACTIONTIONPERFORMED(ACTION EVENT) method:
Q3. How do i get member array elements displayed into the Textfield?
Code Behind the DELETE button i.e. in the VOID DELETE_ACTIONTIONPERFORMED(ACTION EVENT) method:
Q4. Deleting user selected elements?
thanks for your time
Q1.How do i create an array of type member?
Is it: MEMBER X[] = NEW MEMBER[100]; Not unless MEMBER is final, which would be inappropriate here + I'd advise the word 'new' though not 'NEW'.
If so Where does this statement go?In your source code file
Q2.How do i allow the user to keep adding more members
every time the add button is pressed?By having source code that creates the conditions for this
>
Code Behind the DISPLAY button i.e. in the VOID
DISPLAY_ACTIONTIONPERFORMED(ACTION EVENT) method:Again these are not final methods, they are overrided methods
Q3. How do i get member array elements displayed into
the Textfield?This goes back to the thorny issue of writing code again. It's generally quite hard to do this sort of thing without it.
>
Code Behind the DELETE button i.e. in the VOID
DELETE_ACTIONTIONPERFORMED(ACTION EVENT) method:Again, this is overriden, so final declarations are not permitted
Q4. Deleting user selected elements?See above, re: source code.
thanks for your time Welcome, we're here to help
Similar Messages
-
I am trying to use and education program that needs Java applets and it will not run on Safari. IE will not install from the web. How do I get a browser that will work to install so I can use this program when I travel.
Try using FireFox. IE will only run on a Mac if you run Windows on the Mac.
Windows on Intel Macs
There are presently several alternatives for running Windows on Intel Macs.
Install the Apple Boot Camp software. Purchase Windows 7 or Windows 8. Follow instructions in the Boot Camp documentation on installation of Boot Camp, creating Driver CD, and installing Windows. Boot Camp enables you to boot the computer into OS X or Windows.
Parallels Desktop for Mac and Windows XP, Vista Business, Vista Ultimate, or Windows 7. Parallels is software virtualization that enables running Windows concurrently with OS X.
VM Fusion and Windows XP, Vista Business, Vista Ultimate, or Windows 7. VM Fusion is software virtualization that enables running Windows concurrently with OS X.
CrossOver which enables running many Windows applications without having to install Windows. The Windows applications can run concurrently with OS X.
VirtualBox is a new Open Source freeware virtual machine such as VM Fusion and Parallels that was developed by Solaris. It is not as fully developed for the Mac as Parallels and VM Fusion.
Note that Parallels and VM Fusion can also run other operating systems such as Linux, Unix, OS/2, Solaris, etc. There are performance differences between dual-boot systems and virtualization. The latter tend to be a little slower (not much) and do not provide the video performance of the dual-boot system. See MacTech.com's Virtualization Benchmarking for comparisons of Boot Camp, Parallels, and VM Fusion. A more recent comparison of Parallels, VM Fusion, and Virtual Box is found at Virtualization Benchmarks- Parallels 10 vs. Fusion 7 vs. VirtualBox. Boot Camp is only available with Leopard and later. Except for Crossover and a couple of similar alternatives like DarWine you must have a valid installer disc for Windows.
You must also have an internal optical drive for installing Windows. Windows cannot be installed from an external optical drive. -
Help!!! Need Java Applet to work in IE
I found some applets (text scrollers) from the sun site that i wanted to use. downloaded them, but they do not work in IE that does not have JVM. in IE that does have JVM it says 'Java 1.1 Required' where the applet should be. is there a simple way to get sun java applets to work with IE and the MS Virtual Machine? I can't require my site visitors to have to download extra toys/plugins...
If you are looking for a purely AWT scrolling applet. Here is one I wrote several years ago. Please note that there are some deprecated methods in it (mainly the thread start and stop methods). It will still compile though. If you want it, take it.
Source:import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
public class ScrollApplet extends Applet implements Runnable
/*=*********************
* private data members *
private Thread myThread = null;
private boolean hasTextDisplayed;
private int appletWidth, appletHeight;
private int yPosition;
private int xPosition;
private Image textImage;
private int imageWidth;
private Graphics textGraphics;
private Cursor oldCursor;
private Cursor newCursor = new Cursor(Cursor.HAND_CURSOR);
//parameters
private int delay;
private String displayText;
private Color bgColor, fgColor;
private int fontSize, fontStyle;
private Font fontType;
private String urlValue;
/*=***************
* applet methods *
public void init()
//assign values to private data members
hasTextDisplayed = false;
appletHeight = yPosition = getSize().height;
appletWidth = xPosition = getSize().width;
//set up the environment
extractParameters();
//determine the yPosition to place the image
calculateYPosition();
//set up the text image
FontMetrics fm = getFontMetrics(fontType);
imageWidth = fm.stringWidth(displayText);
textImage = createImage(imageWidth, appletHeight);
textGraphics = textImage.getGraphics();
textGraphics.setColor(bgColor);
textGraphics.fillRect(0,0,imageWidth,appletHeight);
textGraphics.setColor(fgColor);
textGraphics.setFont(fontType);
textGraphics.drawString(displayText, 0, yPosition);
oldCursor = this.getCursor();
addMouseListener(new MouseAdapter() {
public void mouseExited(MouseEvent e)
if (urlValue != null) {
Component thisApplet = e.getComponent();
thisApplet.setCursor(oldCursor);
showStatus(" ");
myThread.resume();
public void mouseEntered(MouseEvent e)
myThread.suspend();
if (urlValue != null) {
Component thisApplet = e.getComponent();
thisApplet.setCursor(newCursor);
showStatus(urlValue);
else
showStatus("paused");
public void mouseClicked(MouseEvent e)
if (urlValue != null)
try {
URL u = new URL(urlValue);
getAppletContext().showDocument(u, "_self");
} catch(MalformedURLException ex) {
showStatus("MalformedURLException: " +ex);
}//end init method
public void start()
myThread = new Thread(this);
myThread.start();
}//end start method
public void update(Graphics g)
//overwrote this method to avoid repainting of background before all text displays
if (hasTextDisplayed == true)
//repaint the background
g.setColor(bgColor);
g.fillRect(xPosition+imageWidth, 0, appletWidth - (xPosition + imageWidth),
appletHeight);
g.setColor(fgColor);
paint(g);
}//end update method
public void paint(Graphics g)
setBackground(bgColor);
g.drawImage(textImage,xPosition,0,this);
}//end paint method
public void stop()
{ myThread = null; }
/*=*******************************************************************************
* applet method getParameterInfo(): *
* Returns information about the parameters that are understood by this applet. *
* An applet should override this method to return an array of Strings describing *
* these parameters. Each element of the array should be a set of three Strings *
* containing the name, the type, and a description. *
public String[][] getParameterInfo()
String parameterInfo[][] = {
{"DELAYPARAM", "int", "The interval to pause in milliseconds"},
{"TEXTPARAM", "string", "The text that will be displayed"},
{"BGPARAM", "Color", "The bg color for the applet, in html format #FFFFFF"},
{"FGPARAM", "Color", "The fg color for the text, in html format #FFFFFF"},
{"FONTSIZEPARAM", "int", "The font size of the text"},
{"FONTTYPEPARAM", "string", "The name of the font to use"},
{"FONTSTYLEPARAM", "string", "bold, italic, or bold+italic"},
{"URLPARAM", "string", "hyperlink"}
return parameterInfo;
}//end getParameterInfo method
/*=*****************************************************************************
* applet method getAppletInfo(): *
* Returns information about this applet. An applet should override this method *
* to return a String containing information about the author, version, and *
* copyright of the applet. *
public String getAppletInfo()
String infoAboutMe;
infoAboutMe = new String(
"Author: Your Name Here/n" +
"Description: My first text scroller\n" +
"Version: 1.0"
return infoAboutMe;
}//end getAppletInfo method
/*=***************
* thread methods *
public void run()
Thread current = Thread.currentThread();
//loop until thread is stopped
while (myThread == current)
repaint();
try {
current.sleep(delay);
xPosition--;
} catch (InterruptedException e) {}
if (xPosition <= (appletWidth - imageWidth))
hasTextDisplayed = true;
else
hasTextDisplayed = false;
if (xPosition == (0 - imageWidth))
xPosition = appletWidth;
}//end required run method
/*=**********************************************************************
* extractParameters(): Sets all parameter values, if any were provided *
public void extractParameters()
String delayValue = getParameter("DELAYPARAM");
String textValue = getParameter("TEXTPARAM");
String bgColorValue = getParameter("BGPARAM");
String fgColorValue = getParameter("FGPARAM");
String fontSizeValue = getParameter("FONTSIZEPARAM");
String fontTypeValue = getParameter("FONTTYPEPARAM");
String fontStyleValue = getParameter("FONTSTYLEPARAM");
String urlParam = getParameter("URLPARAM");
//set delay to one tenth of a second if missing parameter
delay = ((delayValue == null) ? 100 : Integer.parseInt(delayValue));
urlValue = (urlParam == null ? null : urlParam);
displayText = ((textValue == null) ?
new String("NO TEXT WAS PROVIDED!") :
textValue);
bgColor = determineColor(bgColorValue);
fgColor = determineColor(fgColorValue);
fontStyle = determineFontStyle(fontStyleValue);
fontSize = ((fontSizeValue == null) ? 12 : Integer.parseInt(fontSizeValue));
fontType = new Font(fontTypeValue, fontStyle, fontSize);
}//end extractParameters method
/*=*************************************************
* determineColor(): returns the appropriate color *
public Color determineColor(String value)
return parseHTMLHex(value);
}//end determineColor method
/*=*****************************************************************************
* parseHTMLHex(): parses an HTML hex (eg #FFFFFF) and returns the Color object *
public static Color parseHTMLHex(String htmlHex) {
Color color = new Color(220,220,220); //default grey
if (htmlHex != null) {
String red = htmlHex.substring(1,3);
String green = htmlHex.substring(3,5);
String blue = htmlHex.substring(5);
color = new Color(Integer.parseInt(red,16),
Integer.parseInt(green,16),
Integer.parseInt(blue,16));
}//end if
return color;
}//end parseHTMLHex method
/*=******************************************
* determineFontStyle(): returns font sytle *
public int determineFontStyle(String value)
int returnVal;
if (value == null)
returnVal = Font.PLAIN;
else if (value.equalsIgnoreCase("plain"))
returnVal = Font.PLAIN;
else if (value.equalsIgnoreCase("bold"))
returnVal = Font.BOLD;
else if (value.equalsIgnoreCase("italic"))
returnVal = Font.ITALIC;
else if (value.equalsIgnoreCase("bold+italic"))
returnVal = Font.BOLD + Font.ITALIC;
else
returnVal = Font.PLAIN;
return returnVal;
}//end determineFontStyle method
/*=**********************************************************
* calculateYPosition(): want text to be in middle of applet *
public void calculateYPosition()
//wasYPositionCalculated = true;
//make calculations to center font in applet window
int appletMidHeight = appletHeight / 2; //the middle of the applet
FontMetrics fm = getFontMetrics(fontType); //font metrics for current font
int fontMidHeight = fm.getAscent() / 2; //the middle of the font
int currentFontSizeValue; //temp value for font size
//if the font size if too big, fix it
if ((currentFontSizeValue = fm.getAscent()) > appletHeight)
//cycle through font sizes until find one that fits
while (currentFontSizeValue > appletHeight)
fontType = new Font(getParameter("FONTTYPEPARAM"), fontStyle, --fontSize);
fm = getFontMetrics(fontType);
currentFontSizeValue = fm.getAscent();
//set the new values for the new font
setFont(fontType);
fm = getFontMetrics(fontType);
fontMidHeight = fm.getAscent() / 2;
yPosition = appletMidHeight + fontMidHeight - 3;
}//end calculateYPosition()
}//end applethtml:<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Test scroller applet</title>
</head>
<BODY>
<h1>Scroller Applet</h1>
<!--CODEBASE = "."-->
<APPLET
CODE = "ScrollApplet.class"
NAME = "TestApplet"
WIDTH = 400
HEIGHT = 30
HSPACE = 0
VSPACE = 0
ALIGN = middle
>
<PARAM NAME="DELAYPARAM" VALUE="10">
<PARAM NAME="TEXTPARAM" VALUE="Simple Old Scrolling Applet?">
<PARAM NAME="BGPARAM" VALUE="#000000">
<PARAM NAME="FGPARAM" VALUE="#CCCCCC">
<PARAM NAME="FONTSIZEPARAM" VALUE="24">
<PARAM NAME="FONTTYPEPARAM" VALUE="TimesRoman">
<PARAM NAME="FONTSTYLEPARAM" VALUE="italic">
<PARAM NAME="URLPARAM" VALUE="http://quote.yahoo.com/quotes?SYMBOLS=DISH">
</applet>
</body>
</html>tajenkins -
Java applet help for mountain lion update on macbook pro
Hey, I upgraded to the new mountain lion update yesterday and since then when opening java applets, it won't allow me to do anything with them such as entering usernames and passwords. It was working fine yesterday before I did the update but now I can't seem to get it to work. I've reinstalled Java and it says it's all installed correctly. I was wondering if anyone else is having/had the same problem and knows what to do?
Thanks in advanceHi Leonie! I was running into the same problem on my Macbook Air with ML but I just found a soultion that worked for me.
I downloaded and installed Java 7 from oracle's website. And then in the java prefences referenced before, changed the Java 7 build to be my default.
All my applets work great now for me.
Hope this helps! -
iam trying to put the checkboxes in different line
so all the checkbox is alligned
what the syntax to do that??
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class Computers extends Applet implements ActionListener
//declare varibles
double totalCost;
//contruct Label and Checkboxes
Label companyName = new Label ("REASONABLE COMPUTER CORPORATION");
Label system = new Label ("Basic Computer System cost: $575");
Label choice = new Label ("Select the peripheral devices you want add");
CheckboxGroup selectGroup = new CheckboxGroup();
Checkbox printers = new Checkbox("Printer $150",false,selectGroup);
Checkbox monitors = new Checkbox("Monitor $300",false,selectGroup);
Checkbox modems = new Checkbox("Modems $100",false,selectGroup);
Checkbox speaker = new Checkbox("Speaker $20",false,selectGroup);
Checkbox microphone = new Checkbox("MircoPhone $15",false,selectGroup);
Checkbox external = new Checkbox ("250G external hard driver $200",false,selectGroup);
Button calc = new Button("Calculate");
Label output = new Label("Click Calculate to see your final price");
//init method for adding the stuff
public void init()
setBackground(Color.green);
setForeground(Color.black);
add(companyName);
add(system);
add(choice);
add(printers);
add(monitors);
add(modems);
add(speaker);
add(microphone);
add(external);
add(calc);
calc.addActionListener(this);
add(output);
public void actionPerformed(ActionEvent e)
totalCost = 575 + getCode();
output(totalCost);
public double getCode()
double dollars = 0;
if (printers.getState()) dollars += 150;
else if (monitors.getState()) dollars += 300;
else if (modems.getState()) dollars += 100;
else if (speaker.getState()) dollars += 20;
else if (microphone.getState()) dollars += 15;
else if (external.getState()) dollars += 200;
return dollars;
public void output(double totalCost)
output.setText("Your Final cost is: " + totalCost + ".");
}hiddendragon wrote:
iam trying to put the checkboxes in different line
so all the checkbox is alligned
what the syntax to do that??There's no "syntax" involved. Instead you have to read up on and study the various layout managers. You could for instance use a BoxLayout to stack information on top of each other, and put your checkboxes in their own panel that uses flowlayout. There's many many ways to arrange this, and the best is the one that works for you. Start here . -
Simple java applet help needed
hi, im having trouble with an applet im developing for a project.
i have developed an applet with asks the user for simple information( name,address and phone) through textfields, i wish for the applet to store this information in an array when an add button below the textfeilds is pressed.
client array[];
array=new client[];//needs to be an infinate array!
I have created the client class with all the set and get methods plus constructors needed but i dont know how to take the text typed into the textfields by the user and store them in the array.
i also need to save this info to a file and be able to load it back into the applet.
Could some please help! Thank you for your time.Better maybe redefine the idea using an data structure :
public class client{
private char name[];
private char address[];
private int phone;
public class vector_clients{
private client vect[];
// methods for vect[]
What is your opinion about ??? -
Have installed Mountain Lion and need Java. Help
Hi,
I installed Mountain Lion this past week.
I am subscribed to two games sites. They both require me to have Java to use them.
I read after I installed ML that there is no Java in this. However, I guess I still had the Apple Java from Snow Leopard.
But, I thought I had to install Java 7 (think at some point I was asked to update Java and it took me to that.
I then read that Chrome can't use the Java I had installed.
So I then tried to use Safari.
Then I picked up FireFox again. I used to have FireFox but had not used it in a while.
Finally managed to get FireFox to run the one site. Quadplex.
However nothing would allow me to use Pogo. I can get to the main page on Pogo, but when I try to activate the games there, it sits and loads and loads and eventually as it SHOULD open it just up and disappears!
Eventually in some of my searching, I read that Java 7 is not secure. That there is a security issue in it.
I searched until I found where I could uninstall Java 7. And I did that. Then I clicked on the link that said I could install the Apple Java that I had managed to get rid of originally (well I assume it is gone since even after a restart, Safari does not let me play anything requiring Java.
I tried to reinstall the Apple Java and got to what I had read was the "terminal". I began to try the commands that were posted on the Apple support page I was on, but it asked for an Administrator Password. To my knowledge I have never had that on my Mac. I usually just click where the window pops up to ask for it and that window goes away and I can install anything without entering any password. But in the "terminal" I tried to just click on the return to go to the next step in the commands routine and it would not allow me to continue.
I am on a MacPro 15" purchased in August 2009 and which has been refurbished due to me having spilled a drink all over the keys area of it in November of 2010. It has been working great until I went ahead and installed Mountain Lion and now have removed the Java download as I read it is not secure and can expose Mac users to something refered to as "drive by" viruses.
I am really at a loss here. The tech I would normally go to may or may not be available this week and I really am frustrated by missing out on my daily gaming.
Any one here who can help with my problem?
Thanks, Carine (aka catonwheels)Thanks Baltwo...and yes it did...by the time I got your response (and it was great that you sent it!) I had already FINALLY found that I needed 7u11 and then found THAT! I had tried to find it after reading about it somewhere during my surfing for a solution but couldn't seem to find it and then when I clicked on an update link SOMEWHERE I was taken right to it. I remembered that the original Java I had downloaded did not have 11 in it and so I downloaded the one that was at that link where I was taken and voila! It worked...however, had I NOT found it having you respond to my help plea would have fixed it and I thank you for taking the time. I had gone to Oracle originally to find this update but somehow I did not get it the first time round. So this would have been great had I not fallen over it when I did. Again, thank you and now at least I am in this community and will have a lot of support and info when I need it! :-)
-
Hi All,
I need your hlep...
I have a javamapping where it should read the webservice response and transform into the target structure..
Webservice response is
<?xml version="1.0" encoding="UTF-8"?>
<ns1:MT_WS_Response xmlns:ns1="http://RFC_Lookup/XI">
<row>
<ID>001</ID>
<KEY>Matnr</KEY>
<VALUE>34567</VALUE>
</row>
<row>
<ID>002</ID>
<KEY>Matnr</KEY>
<VALUE>34567</VALUE>
</row>
<row>
<ID>003</ID>
<KEY>Matn33</KEY>
<VALUE>34567</VALUE>
</row>
</ns1:MT_WS_Response>
I should read the above structure and output it into a payload string variable ...
i have declared variables also
public void execute(InputStream in, OutputStream out)
try
trace.addInfo("Start of Extraction");
OutputStream temp = new ByteArrayOutputStream(1024);
byte[] buffer = new byte[1024];
for (int read = in.read(buffer); read > 0; read = in.read(buffer))
temp.write(buffer, 0, read);
String Payload = temp.toString();
final String STARTTAG = "<row>";
final String ENDTAG = "</row>";
int Y_FILENAME_START = Payload.indexOf(STARTTAG);
int Y_FILENAME_END = Payload.indexOf(ENDTAG);
int spos = Y_FILENAME_START+STARTTAG.length();
<b>if ( ( Y_FILENAME_END > spos) && (Y_FILENAME_END > 0 ) )</b> {
Payload = Payload.substring(Y_FILENAME_START+STARTTAG.length() , Y_FILENAME_END);
trace.addInfo("Sucessfully Extracted");
Please suggest whether how can i read multiple rows .. as i am ABAPER i am unable to do it in Java..
I think the bold one reads only single row ... please suggest for reading multiple rows...
Thanks and Regards,
sridhar reddy
Message was edited by:
sridhar reddy kondamPlease tell us what is the expected target structure.
Also, avoid to treat xml like strings. Use parsing methods (SAX, DOM). It is way easier, and they are mainly the reason why you should use java mappings over ABAP mappings.
Regards,
Henrique. -
im following the java tutorial at their web site online. I'm having problems with these simple applets:
http://java.sun.com/docs/books/tuto...kMeApplets.html
I compiled them fine on my other computer, but when I compiled them on the computer I am using presently, I get a problem.
the files seem to compile fine. but when i compare them with the files online, my files that i compiled are a little less in size. when i load the applet in the provided html file, all i get is a blank gray screen. and when i move the mouse over the gray screen, it says for a split second: "load: class ClickMe not found"
i have all the correct files...but after compiling the .java files, it doesn't work. the .class files on the web work fine. but my compiled files seem to be smaller than those on the web.
the ClickMe.class file i compiled is 1.45 KB (1,494 bytes)
the Spot.class file i compiled is 293 bytes (293 bytes)
the ClickMe.class file online is 1.50 KB (1,539 bytes)
the Spot.class file online is 339 bytes (339 bytes)I believe that one (or more) of these applats are currently broken - the files are mislocated, I believe. Just skip the clickme applets (unless you want to debug them yourself).
-
good evening everybody
iam new to JavaMail
i used an example from oracle site that uses JavaMail to send an email, the applications tells me that the email has been sent successfully, but sadly i did't find any new emails in the email inbox i sent to......... i don't know the reasone...........
the second thing is . is it important to write the password of the email i want to send from ????
the last thing, what is the mail server i have to put when i use hotmail for example ........
thanks
and here is the code
package myClasses;
import javax.mail.*; //JavaMail packages
import javax.mail.internet.*; //JavaMail Internet packages
import java.util.*; //Java Util packages
public class SendMailBean {
public String send(String p_from, String p_to, String p_cc, String p_bcc,String p_subject, String p_message, String p_smtpServer) {
String l_result = "<BR><BR><BR><BR><BR><BR><BR>";
// Name of the Host machine where the SMTP server is running
String l_host = p_smtpServer;
// Gets the System properties
Properties l_props = System.getProperties();
// Puts the SMTP server name to properties object
l_props.put("mail.smtp.host", l_host);
// Get the default Session using Properties Object
Session l_session = Session.getDefaultInstance(l_props, null);
l_session.setDebug(true); // Enable the debug mode
try {
MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
l_msg.setFrom(new InternetAddress(p_from)); // Set the From address
// Setting the "To recipients" addresses
l_msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(p_to, false));
// Setting the "Cc recipients" addresses
l_msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(p_cc, false));
// Setting the "BCc recipients" addresses
l_msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(p_bcc, false));
l_msg.setSubject(p_subject); // Sets the Subject
// Create and fill the first message part
MimeBodyPart l_mbp = new MimeBodyPart();
l_mbp.setText(p_message);
// Create the Multipart and its parts to it
Multipart l_mp = new MimeMultipart();
l_mp.addBodyPart(l_mbp);
// Add the Multipart to the message
l_msg.setContent(l_mp);
// Set the Date: header
l_msg.setSentDate(new Date());
// Send the message
Transport.send(l_msg);
// If here, then message is successfully sent.
// Display Success message
l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"><B>Success!</B>"+
"<FONT SIZE=4 COLOR=\"black\"> "+
"<HR><FONT color=green><B>Mail was successfully sent to </B></FONT>: "+p_to+"<BR>";
//if CCed then, add html for displaying info
if (!p_cc.equals(""))
l_result = l_result +"<FONT color=green><B>CCed To </B></FONT>: "+p_cc+"<BR>";
//if BCCed then, add html for displaying info
if (!p_bcc.equals(""))
l_result = l_result +"<FONT color=green><B>BCCed To </B></FONT>: "+p_bcc ;
l_result = l_result+"<BR><HR>";
} catch (MessagingException mex) { // Trap the MessagingException Error
// If here, then error in sending Mail. Display Error message.
l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
"<FONT SIZE=3 COLOR=\"black\">"+mex.toString()+"<BR><HR>";
} catch (Exception e) {
// If here, then error in sending Mail. Display Error message.
l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
"<FONT SIZE=3 COLOR=\"black\">"+e.toString()+"<BR><HR>";
e.printStackTrace();
}//end catch block
finally {
return l_result;
} // end of method send
} //end of beangood evening everybody
iam new to JavaMailDon't forget to read the JavaMail FAQ!
i used an example from oracle site that uses JavaMail
to send an email, the applications tells me that the
email has been sent successfully, but sadly i did't
find any new emails in the email inbox i sent
to......... i don't know the reasone...........Turn on session debugging and examine the protocol
trace. It might provide some clues. If it still seems like
the server is accepting the message without complaint,
the problem is in your mail server, or perhaps in any filters
you have on your incoming mail. Check the mail server
log file for clues.
the second thing is . is it important to write the
password of the email i want to send from ????Maybe. It depends on whether your mail server requires
authentication or not.
the last thing, what is the mail server i have to put
when i use hotmail for example ........I don't know, check the hotmail web site for information
about how to configure your mail client. Last time I looked,
hotmail didn't even support such usage. -
URGETN HELP NEEDED! JAVA APPLET READING FILE
Hi everyone
I need to hand in this assignment today
Im trying to read from a file and read it onto the screen, my code keeps showing up an error
'missing method body, or declare abstract'
This is coming up for the
public statuc void main(String[] args);
and the
public void init();
Here is my code:
import java.io.*;
import java.awt.*;
import java.applet.*;
public class Empty_3 extends Applet {
TextArea ta = new TextArea();
public static void main(String[] args);
public void init();
setLayout(new BorderLayout());
add(ta, BorderLayout.CENTER);
try {
InputStream in =
getClass().getResourceAsStream("test1.txt");
InputStreamReader isr =
new InputStreamReader(in);
BufferedReader br =
new BufferedReader(isr);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
String line;
while ((line = br.readLine()) != null) {
pw.println(line);
ta.setText(sw.toString());
} catch (IOException io) {
ta.setText("Ooops");
Can anyone help me please?
Is this the best way of doing this? Once i read the file i want to perform a frequency analysis on the words so if there is a better method for this then please let me know!
Thankyou
MattWhether it is urgent or not, does not interest us. It might be urgent for you but for nobody else.
Writing all-capitals is considered shouting and rude.
// Use code tags for source. -
Absolute Beginner needs help with applet
Hello folks,
I know I have already started a topic on this, but it was getting a bit long and I wasn't getting anywhere with it. Here's my problem... first of all, I am new to Java, especially with Applets. I attempted to create the HelloWorld applet from this site's First Cup of Java tutorial. I was able to compile the java file fine, but when I attemted to add the applet to an html file, I get a message at the bottom taskbar saying "load: class HelloWorld not found". I can't figure out what is wrong with my code. I have all my files (html, java, and class files) in one folder, with no subfolders at all. In case it matters, I'm on a Windows 98 machine with IE 6.0 for my browser. Here is the code:
First my HelloWorld.java file, which, as I said, compiles with no problems
import java.applet.*;
import java.awt.*;
* The HelloWorld class implements an applet that
* simply displays "Hello World!".
public class HelloWorld extends Applet {
public void paint (Graphics g) {
//Display "Hello World!"
g.drawString("Hello World!", 50, 25);
}And here is the HTML file which is supposed to display the applet:
<html>
<head>
<title>A Simple Program</title>
</head>
<body>
Here is the output of my program:
<applet code="HelloWorld.class" width="150" height="25">
</applet>
</body>
</html>Can someone please check this and see what, if anything, is wrong?Hi Chris,
This isn't going to help much. I took your Java code
and put it in a file HelloWorld.java. I took your HTML
code and put it in a file HelloWorld.html. I compiled
HelloWorld.java with javac so that I had HelloWorld.class.
I then ran the program with appletviewer by typing
appletviewer HelloWorld.html.
It loaded and ran fine.
Since that sounds like exactly what you are doing,
I'm not sure what else to suggest. (I could also
run it by opening the HTML file with IE.)
There are only two things that still suggest themselves,
and they seem like long-shots:
1) Is the file named HelloWorld.java that contains your
code (including the capital W)? This is obviously a
long-shot because your code shouldn't compile if this
was set incorrectly.
2) Is it possible that you have the CLASSPATH environmental
variable set? Some programs (like QuickTime for Java)
will set the CLASSPATH and then Java just stops working.
You can find out by typing SET at the command prompt and
looking for CLASSPATH. If you find it, then you'll probably
need to remove it from your AUTOEXEC.BAT (in Windows 98),
or update it to include the runtime classes for the SDK.
--Steve -
Need help with Java applet, might need NetBeans URL
I posted the below question. It was never answered, only I was told to post to the NetBeans help forum. Yet I don't see any such forum on this site. Can someone tell me where the NetBeans help forum is located (URL).
Here is my original question:
I have some Java source code from a book that I want to compile. The name of the file is HashTest.java. In order to compile and run this Java program I created a project in the NetBeans IDE named javaapplication16, and I created a class named HashTest. Once the project was created, I cut and pasted the below source code into my java file that was default created for HashTest.java.
Now I can compile and build the project with no errors, but when I try and run it, I get a dialog box that says the following below (Ignore the [...])
[..................Dialog Box......................................]
Hash Test class wasn't found in JavaApplication16 project
Select the main class:
<No main classes found>
[..................Dialog Box......................................]
Does anyone know what the problem is here? Why won't the project run?
// Here is the source code: *****************************************************************************************************
import java.applet.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.util.*;
public class HashTest extends Applet implements ItemListener
// public static void main(String[] args) {
// Hashtable to add tile images
private Hashtable imageTable;
// a Choice of the various tile images
private Choice selections;
// assume tiles will have the same width and height; this represents
// both a tile's width and height
private int imageSize;
// filename description of our images
private final String[] filenames = { "cement.gif", "dirt.gif", "grass.gif",
"pebbles.gif", "stone.gif", "water.gif" };
// initializes the Applet
public void init()
int n = filenames.length;
// create a new Hashtable with n members
imageTable = new Hashtable(n);
// create the Choice
selections = new Choice();
// create a Panel to add our choice at the bottom of the window
Panel p = new Panel();
p.add(selections, BorderLayout.SOUTH);
p.setBackground(Color.RED);
// add the Choice to the applet and register the ItemListener
setLayout(new BorderLayout());
add(p, BorderLayout.SOUTH);
selections.addItemListener(this);
// allocate memory for the images and load 'em in
for(int i = 0; i < n; i++)
Image img = getImage(getCodeBase(), filenames);
while(img.getWidth(this) < 0);
// add the image to the Hashtable and the Choice
imageTable.put(filenames[i], img);
selections.add(filenames[i]);
// set the imageSize field
if(i == 0)
imageSize = img.getWidth(this);
} // init
// tiles the currently selected tile image within the Applet
public void paint(Graphics g)
// cast the sent Graphics context to get a usable Graphics2D object
Graphics2D g2d = (Graphics2D)g;
// save the Applet's width and height
int width = getSize().width;
int height = getSize().height;
// create an AffineTransform to place tile images
AffineTransform at = new AffineTransform();
// get the currently selected tile image
Image currImage = (Image)imageTable.get(selections.getSelectedItem());
// tile the image throughout the Applet
int y = 0;
while(y < height)
int x = 0;
while(x < width)
at.setToTranslation(x, y);
// draw the image
g2d.drawImage(currImage, at, this);
x += imageSize;
y += imageSize;
} // paint
// called when the tile image Choice is changed
public void itemStateChanged(ItemEvent e)
// our drop box has changed-- redraw the scene
repaint();
} // HashTestBigDaddyLoveHandles wrote:
h1. {color:red}MULTIPOST: [http://forums.sun.com/thread.jspa?threadID=5358840&messageID=10564025]{color}
That wasn't attention-grabbing enough apparantly. Let's try it again.
h1. {color:red}MULTIPOST: [http://forums.sun.com/thread.jspa?threadID=5358840&messageID=10564025]{color}
h1. {color:red}MULTIPOST: [http://forums.sun.com/thread.jspa?threadID=5358840&messageID=10564025]{color}
h1. {color:red}MULTIPOST: [http://forums.sun.com/thread.jspa?threadID=5358840&messageID=10564025]{color}
h1. {color:red}MULTIPOST: [http://forums.sun.com/thread.jspa?threadID=5358840&messageID=10564025]{color}
h1. {color:red}MULTIPOST: [http://forums.sun.com/thread.jspa?threadID=5358840&messageID=10564025]{color} -
�� I have a java applet program (yanhua.java) need help!!!
�� I have a java applet program (yanhua.java) that use mouse click a area show a fireworks, the applet program that a java fan mail me. Now i find some bug in the program, can you help me? thank in advance!
The backdrop of the question: The yanhua.java applet program works well. But one day, i install j2re 1.4.1 plugin for my microsfot Internet Explorer, i run the yanhua.java applet program again, it show difficult(i move my mouse in the area, slowness), the fireworks is not fluent. Then i try my best to find the cause , i get some information, the following: yanhua.java run in j2re 1.4.1 plugin,it will deplete 100% cpu; else yanhua.java does not run in j2re 1.4.1 plugin, it will deplete 90%--95% cpu too; but my computer c3 1G cpu and 256MB memory, without running other program at that time. So i can have the assurance to say that the yanhua.java have some bug or error. can you help me to find all bug in yanhua.java? thank you very much!!!
i want to solve the question: finding all bug in yanhua.java
NOTE:
1��fireworks show specially good effect(a yanhua.java applet) you can look at:
http://www.3ren.net/down/java/yanhua.html
2��all program you can get from http://www.3ren.net/down/java/yanhua.rar
/*************************yanhua.java******************************
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.image.MemoryImageSource;
import java.util.Random;
public class yanhua extends Applet
implements Runnable
private int m_nAppX;
private int m_nAppY;
private int m_centerX;
private int m_centerY;
private int m_mouseX;
private int m_mouseY;
private int m_sleepTime;
private boolean isError;
private boolean m_isPaintFinished;
boolean isRunning;
boolean isInitialized;
Thread runner;
int pix0[];
MemoryImageSource offImage;
Image dbImg;
int pixls;
int pixls2;
Random rand;
int bits;
double bit_px[];
double bit_py[];
double bit_vx[];
double bit_vy[];
int bit_sx[];
int bit_sy[];
int bit_l[];
int bit_f[];
int bit_p[];
int bit_c[];
int bit_max;
int bit_sound;
int ru;
int rv;
AudioClip sound1;
AudioClip sound2;
public yanhua()
m_mouseX = 0;
m_mouseY = 0;
m_sleepTime = 5;
isError = false;
isInitialized = false;
rand = new Random();
bits = 10000;
bit_px = new double[bits];
bit_py = new double[bits];
bit_vx = new double[bits];
bit_vy = new double[bits];
bit_sx = new int[bits];
bit_sy = new int[bits];
bit_l = new int[bits];
bit_f = new int[bits];
bit_p = new int[bits];
bit_c = new int[bits];
ru = 50;
rv = 50;
public void init()
String s = getParameter("para_bits");
if(s != null)
bits = Integer.parseInt(s);
s = getParameter("para_max");
if(s != null)
bit_max = Integer.parseInt(s);
s = getParameter("para_blendx");
if(s != null)
ru = Integer.parseInt(s);
s = getParameter("para_blendy");
if(s != null)
rv = Integer.parseInt(s);
s = getParameter("para_sound");
if(s != null)
bit_sound = Integer.parseInt(s);
m_nAppX = this.getSize().width;
m_nAppY = this.getSize().height;
m_centerX = m_nAppX / 2;
m_centerY = m_nAppY / 2;
m_mouseX = m_centerX;
m_mouseY = m_centerY;
resize(m_nAppX, m_nAppY);
pixls = m_nAppX * m_nAppY;
pixls2 = pixls - m_nAppX * 2;
pix0 = new int[pixls];
offImage = new MemoryImageSource(m_nAppX, m_nAppY, pix0, 0, m_nAppX);
offImage.setAnimated(true);
dbImg = createImage(offImage);
for(int i = 0; i < pixls; i++)
pix0[i] = 0xff000000;
sound1 = getAudioClip(getDocumentBase(), "firework.au");
sound2 = getAudioClip(getDocumentBase(), "syu.au");
for(int j = 0; j < bits; j++)
bit_f[j] = 0;
isInitialized = true;
start();
public void run()
while(!isInitialized)
try
Thread.sleep(200L);
catch(InterruptedException interruptedexception) { }
do
for(int j = 0; j < pixls2; j++)
int k = pix0[j];
int l = pix0[j + 1];
int i1 = pix0[j + m_nAppX];
int j1 = pix0[j + m_nAppX + 1];
int i = (k & 0xff0000) >> 16;
int k1 = ((((l & 0xff0000) >> 16) - i) * ru >> 8) + i;
i = (k & 0xff00) >> 8;
int l1 = ((((l & 0xff00) >> 8) - i) * ru >> 8) + i;
i = k & 0xff;
int i2 = (((l & 0xff) - i) * ru >> 8) + i;
i = (i1 & 0xff0000) >> 16;
int j2 = ((((j1 & 0xff0000) >> 16) - i) * ru >> 8) + i;
i = (i1 & 0xff00) >> 8;
int k2 = ((((j1 & 0xff00) >> 8) - i) * ru >> 8) + i;
i = i1 & 0xff;
int l2 = (((j1 & 0xff) - i) * ru >> 8) + i;
int i3 = ((j2 - k1) * rv >> 8) + k1;
int j3 = ((k2 - l1) * rv >> 8) + l1;
int k3 = ((l2 - i2) * rv >> 8) + i2;
pix0[j] = i3 << 16 | j3 << 8 | k3 | 0xff000000;
rend();
offImage.newPixels(0, 0, m_nAppX, m_nAppY);
try
Thread.sleep(m_sleepTime);
catch(InterruptedException interruptedexception1) { }
} while(true);
public void update(Graphics g)
paint(g);
public void paint(Graphics g)
g.drawImage(dbImg, 0, 0, this);
public void start()
if(isError)
return;
isRunning = true;
if(runner == null)
runner = new Thread(this);
runner.start();
public void stop()
if(runner != null)
runner.stop();
runner = null;
public boolean mouseMove(Event event, int i, int j)
m_mouseX = i;
m_mouseY = j;
return true;
public boolean mouseDown(Event event, int i, int j)
m_mouseX = i;
m_mouseY = j;
int k = (int)(rand.nextDouble() * 256D);
int l = (int)(rand.nextDouble() * 256D);
int i1 = (int)(rand.nextDouble() * 256D);
int j1 = k << 16 | l << 8 | i1 | 0xff000000;
int k1 = 0;
for(int l1 = 0; l1 < bits; l1++)
if(bit_f[l1] != 0)
continue;
bit_px[l1] = m_mouseX;
bit_py[l1] = m_mouseY;
double d = rand.nextDouble() * 6.2800000000000002D;
double d1 = rand.nextDouble();
bit_vx[l1] = Math.sin(d) * d1;
bit_vy[l1] = Math.cos(d) * d1;
bit_l[l1] = (int)(rand.nextDouble() * 100D) + 100;
bit_p[l1] = (int)(rand.nextDouble() * 3D);
bit_c[l1] = j1;
bit_sx[l1] = m_mouseX;
bit_sy[l1] = m_nAppY - 5;
bit_f[l1] = 2;
if(++k1 == bit_max)
break;
if(bit_sound > 1)
sound2.play();
return true;
public boolean mouseExit(Event event, int i, int j)
m_mouseX = i;
m_mouseY = j;
return true;
void rend()
boolean flag = false;
boolean flag1 = false;
boolean flag2 = false;
for(int k = 0; k < bits; k++)
switch(bit_f[k])
default:
break;
case 1: // '\001'
bit_vy[k] += rand.nextDouble() / 50D;
bit_px[k] += bit_vx[k];
bit_py[k] += bit_vy[k];
bit_l[k]--;
if(bit_l[k] == 0 || bit_px[k] < 0.0D || bit_py[k] < 0.0D || bit_px[k] > (double)m_nAppX || bit_py[k] > (double)(m_nAppY - 3))
bit_c[k] = 0xff000000;
bit_f[k] = 0;
} else
if(bit_p[k] == 0)
if((int)(rand.nextDouble() * 2D) == 0)
bit_set((int)bit_px[k], (int)bit_py[k], -1);
} else
bit_set((int)bit_px[k], (int)bit_py[k], bit_c[k]);
break;
case 2: // '\002'
bit_sy[k] -= 5;
if((double)bit_sy[k] <= bit_py[k])
bit_f[k] = 1;
flag2 = true;
if((int)(rand.nextDouble() * 20D) == 0)
int i = (int)(rand.nextDouble() * 2D);
int j = (int)(rand.nextDouble() * 5D);
bit_set(bit_sx[k] + i, bit_sy[k] + j, -1);
break;
if(flag2 && bit_sound > 0)
sound1.play();
void bit_set(int i, int j, int k)
int l = i + j * m_nAppX;
pix0[l] = k;
/*********************************end*******************************no one help me???????????
-
Newbie need help wtih Java Applet noinit error
Hi, i am having problem with a making this java applet application run, i am new to java but i am sure that my coding is right, because this what i typed from my java class book. Don't know why when i try to run it is say at the bottom of the windows explorer, "applet class name "noinit"". The code is listed below maybe someone could help me figure this out. I used NetBean to compile it, also I have the latest version of java but could not find a applet that come with the newest version of java so I'm using the j2sdk1.4.2_11 applet, and have added it to my system environment path. Maybe that could be the problem if so where do i get the newest version of the applet, because without doing what i did i could run applets in the first place. My other sample applet sample (demo's) that come with Java runs fine without any problem. Only when i run mine i get the message, "applet class name noinit".
HTML file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome Applet</title>
</head>
<!-- Used to load the Java .class file -->
<applet code="WelcomeApplet.class" width="300" height="45">
alt="Your browser understands the <;APPLET> tag but isn't running the applet, for some reason."
Your browser is completely ignoring the <APPLET> tag!
</applet>
<body>
</body>
</html>Java code:
/* Fig. 3.6: WelcomeApplet.java
* My first applet in Java
* Created on May 2, 2006, 2:50 AM
// Java packages
package appletjavafig3_6;
import java.awt.Graphics; // import class Graphics
import javax.swing.JApplet; // import class JApplet
public class WelcomeApplet extends JApplet {
public WelcomeApplet(){
// 3rd method that is called by default
// draw text on applets's background
public void paint( Graphics g)
// call superclass version of method paint
super.paint(g);
// draw a String at x-coordinate 25 and y coordinate 25
g.drawString("Welcome to Java Programming!", 25,25);
} // end method paint
} // WelcomeAppletHi,
Your applet code in the html should be
<applet code="appletjavafig3_6.WelcomeApplet" width="300" height="45">
alt="Your browser understands the <;APPLET> tag but isn't running the applet, for some reason."
Your browser is completely ignoring the <APPLET> tag!
</applet>As the class is inside a package named appletjavafig3_6, put the class file inside a folder named appletjavafig3_6. Put the html file outside this folder and test it.
Maybe you are looking for
-
Insert specific line in an internal table at a specific place
Hi i have an internal table (itab) let's say Name1 Name2 NUM1 NUM2 NUM3 Which already populater with data. i have to do a subtotal for every NAME1 and insert a line just after the NAME1 in the internal table and another subtotal by every NAME1 NAME2
-
I have an IPod, an IPhone and an IPad. ITunes previously opened my device when I connected it to my computer, listing the device in the left column. Now the devices do not appear and I cannot manage my playlists. What has happened?
-
Compact flash reader for apple mac
It will not read my compact flash reader
-
I have a problem with exporting my images from Lightroom 4 to a folder or Photoshop. Please help.
-
If I used external hard disk for back up time machine, is it possible to use that external hard disk to save another else from diffrent computers?