Java Code Help-Palindromes

Sorry to trouble anyone, but I need help with coding a program dealing with Palindromes. I have some of the code already down, but I'm having trouble having the program recognize certain words as Palindromes (e.g. Racecar, madam, etc.). Note that this program is also case-sensitive. So I was just wondering if anyone had any code that could fix this maybe? If you do, it'd be appreciated. Thanks

public static void main(String[] args)
          String strPalin = null;
          if(args[0] != null)
               strPalin = args[0];
          byte[] b = strPalin.getBytes();
          int strlen = b.length;
          int i = (strlen - 1);
          int j = 0;
          byte[] c = new byte[strlen];
          while(i>-1)
               c[j] = b;
               i--;
               j++;
          String strrev = new String(c);
          if(strrev.equals(strPalin))
               System.out.println("Oops its a Palindrome:" +strPalin);
          }else{
               System.out.println("its not a Palindrome: " +strPalin);
hi,
plz check it out , it may serve ur requirement i think .
keep mail to [email protected]

Similar Messages

  • Urgent java code help needed

    i need java code for writing following lines in a file
    <?xml version="1.0"?>
    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml">
    Moreover i need code for reading word by word html file.
    PLease reply as soon as possible.
    iwapsms

    for the html-part there are several html-parser, that bould whole parsetrees, which you can traverse (walk) through as you whish. just check google for it (something like: java html parser).
    if that xml you have there is in String-form, just use a Filewriter
    BufferedWriter writer = new BufferedWriter (new FileWriter (new File ("FilePath/filename.xml")));
    writer.write (xmlString);
    writer.close();however, if you have to juggle xml tags, content and attributes a lot, i'd recomend jdom to construct the xml and saxParser to write it.
    again jsut google for it.

  • Search java code help

    I am writing a small Java program and need help using a simple search code. Here is the code
    public int indexOf(EltType e) {
            int i=0;
            for (i = currsize; i < currsize; i++){
                things[i] = e;
                e.equals(get(i));
            return -1;
        }Basically I want to search the array for e, and return its position, or -1 if e is not found. I know I have to use .equals(i) to compare e and get(i) but unsure where it goes.
    Here is the method that calls it:
    public void searchtester() {
            MyList<String> searchlist = new MyList<String>();
            searchlist.add("tangerine");
            searchlist.add("apple");
            searchlist.add("mango");
            searchlist.add("lime");
            searchlist.add("carrot");
            for (int i = 0; i<searchlist.size(); i++)
            System.out.println("searching for \"" + searchlist.get(i) + "\", result="
                + words.indexOf(searchlist.get(i)));
        }Please let me know what I am doing wrong.

    middle wrote:
    sorry kevinaworkman, not trying to ignore any advice, just very new to java so trying to figure this out. It's okay, I just know from experience that breaking it up into smaller pieces will save you a ton of headaches.
    Ok so I would imagine that loop:
    for (i = currsize; i < currsize; i++)would run onceTake a look at the tutorial on [the for statement|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html] . If i starts out equal to currsize, and is only ever incremented, when will it be less than currsize? But even assuming that the loop runs once, what good would that be? Wouldn't you want the loop to run as many times as there are elements in your array?
    things[i] = e;I'll give you a hint: if this line were executed, it would set the element at position i in the array equal to e. You want to check for equality, not set the whole array equal to e, right? Do you mean == in an if statement?
    e.equals(get(i));Again, if this line was executed, it would check for equality between e and whatever get(i) returns. But then what are you doing with that boolean?
    I want to see if i is equal to e then the result I want is the position of e and if i does not equal e then I want it to result in a -1, the issue is that it is giving me "-1" for all the results when I know that the first 3 items are in the list.You might want to step through your program with a debugger to see what's happening line by line. Or better yet, step through it with a piece of paper and a pencil. Go through the program as if you were the computer, following your program (and not the logic in your head you think the program does) exactly.
    Some other things you might want to consider: the [if statement|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/if.html] , arrays , and the above mentioned for loop tutorials.

  • Very inexperienced Sun Java coder , Help !!!! I  get NullPointerException

    In Sun JKD1.5.0
    programs
    CalculatorInterface.java
    Client.java ==> c[4]
    Account.java ==> a[3]
    CalculatorInterface ==> c[4] objects ==> a[3] objects
    I have in CalculatorInterface.java
    public class CalculatorInterface
    // reference to class Client
    private static final int maxClients = 4;
    // constructor for client[] object array
    private static client[] c = new client[maxClients];
    private static int total,atotal;
    private static int noClients;
    etc
    etc
    public static void main (String[] args)
    parameter definitions
    code lines
    c[noClients] = new client();
    / creates a new instance of client contained in c[]
    total = noClients;
    code lines
    method calls
    noClients++; // next c[]
    termination
    } // end of Main
    CalculatorInterface Methods including
    void WhatIsLeft()
    ... code ...
    ....code...
    c[total].getAccount(atotal).setAmount_IS_Surplus(c[total].calcWeeklySurplus(salaryYrly,weeklyExpenses,isRes));
    ... code...
    The line of code returns a NullPointerException and crashes the program !!! >_<
    is not successfully calling methods in Account.java ..... ?????
    === === === === === === > AND : I have in Client.java
    public class client
    // references to object Account a[]
    private static final int maxAccounts = 3;
    private Account[] a = new Account[maxAccounts]; //? This references a[] to client
    Client Methods including
    public Account getAccount(int num)
    return a[num]; // will be num = 0 or 1 or 2
    } // end client
    === === ==== ===> AND in Account.java
    public class Account
    Account methods
    SO ..... what's the fix ?
    HELP !!!!! I know not what to do to fix this glitch.

    And now I take the chance to ask someone...
    Where is that forum to discuss about the
    forums?
    deleted
    Damn! <sarcasm> I love you Sun. </sarcasm>

  • Java code help needed for If-elseif statement

    HI All,
    Apologies for posting such a trivial thing but I am a novice in Java.
    All I need is to code an If elseIF statement.
    I tried the code below
    String w = "SAPA";
    String x = "SAPB";
    if (a==w) ;
    {Channel channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP");}
    else if (a==x)
    { Channel channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP_ECQ"); }
    It came back with the error
    Source code has syntax error:  D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map695b77619ad011dd8d0b001a4b52813a/source/com/sap/xi/tf/_MM_TRANSMISSION_CHECK_TO_GENIUS_.java:324: 'else' without 'if' else if (a==x) ^ 1 error
    Appreciate if you could let me know the correct code.
    Many thanks
    Shirin

    HI Aamir,
    After I removed the semi-colon iIt came back with the following error
    Source code has syntax error:  D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map1d9b43e09ad111dd84b7001a4b52813a/source/com/sap/xi/tf/_MM_TRANSMISSION_CHECK_TO_GENIUS_.java:328: cannot resolve symbol symbol : variable channel location: class com.sap.xi.tf._MM_TRANSMISSION_CHECK_TO_GENIUS_ accessor = LookupService.getRfcAccessor(channel); ^ 1 error
    Just for reference my entire Jave UDF looks like this:
    //write your code here
    String w = "SAPA";
    String x = "SAPB";
      String content = "";
    MappingTrace importanttrace;
    importanttrace = container.getTrace() ;
    //Filling the string with our RFC-XML (With Values)
    String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:ZIFMS_GET_NEXT_NUMBER xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"><I_NR_RANGE_NR>01</I_NR_RANGE_NR><I_OBJECT>ZIFMS_INT</I_OBJECT></ns0:ZIFMS_GET_NEXT_NUMBER>";
    RfcAccessor accessor = null;
    ByteArrayOutputStream out = null;
    try
    //1. Determine a channel (Business System, Communication channel)
    if (a==w)
    {Channel channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP");}
    else if (a==x)
    { Channel channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP_ECQ"); }
    //2. Get a RFC accesor for a channel.
    accessor = LookupService.getRfcAccessor(channel);
    //3. Create a xml input stream representing the FM request message.
    InputStream inputstream = new ByteArrayInputStream(m.getBytes());
    //4. Create xml Payload
    XmlPayload payload = LookupService.getXmlPayload(inputstream);
    //5. Execute Lookup
    Payload result = accessor.call(payload);
    InputStream in = result.getContent();
    //This are the extra step which i dont know what it mean
    //out = new ByteArrayOutputStream(1024);
    //byte[] buffer = new byte1024;
    //for (int read = in.read(buffer); read > 0; read = in.read(buffer))
    //out.write(buffer,0,read);
    //content = out.toString();
    try {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(in);
    NodeList list = document.getElementsByTagName( "E_NUMBER" );
    Node node = list.item(0);
    if (node != null)
    node = node.getFirstChild();
    if (node != null)
    content = node.getNodeValue();
    } catch (Exception e) {
    importanttrace.addWarning("Error while closing accesor" + e.getMessage());
    catch (LookupException e)
    importanttrace.addWarning("Error While lookup" + e.getMessage());
    //This exception is not to be catch at this step as there is no try step before this
    //catch (IOException e)
    //importanttrace.addWarning("Error" + e.getMessage());
    finally
    if(out!=null)
    try{
    out.close();
    } catch (IOException e) {
    importanttrace.addWarning("Error while closing system" + e.getMessage());
    //7. close the accessor in order to free resources
    if (accessor!=null) {
    try{
    accessor.close();
    } catch (Exception e) {
    importanttrace.addWarning("Error while closing accesor" + e.getMessage());
    return content;

  • Need Java code Help

    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 kondam

    Please 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.

  • Java code help

    I have a class L1 in which I am creating an instance of another class Nav
    like
    Nav nav = new Nav(class.L2);
    the argument in this Nav, shoukd be a class name how can I pass a classname as a argument. is it class.L2 or how?
    In the Nav constructor I want to create a new instance of the class argument that was passed. How can I do this is there a way to do so? Thanks.

    Try with:
    Nav nav = new Nav(L2);
    // this will call the constructor that looks like:
    Nav(Class cl) { ... }

  • Can anybody help on sending mail through Java Code

    I am trying to send the mail using the java code and I am unable to do it. My code is
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.text.*;
    public class EmailExample {
    public static void main(String[] args)
    Socket smtpSocket;
    DataOutputStream os;
    BufferedReader is;
    Date dDate = new Date();
    DateFormat dFormat = DateFormat.getDateInstance(DateFormat.FULL,Locale.US);
    try
    smtpSocket = new Socket("www.gmail.com",80);
    os = new DataOutputStream(smtpSocket.getOutputStream());
    is = new BufferedReader(new InputStreamReader(smtpSocket.getInputStream()));
    System.out.println("Hi How is this?");
    os.writeBytes("HELLO\r\n");
    // You will add the email address that the server
    // you are using know you as.
    os.writeBytes("MAIL From: <[email protected]>\r\n");
    // Who the email is going to.
    os.writeBytes("RCPT To: <[email protected]>\r\n");
    //IF you want to send a CC then you will have to add this
    //os.writeBytes("RCPT Cc: <[email protected]>\r\n");
    // Now we are ready to add the message and the
    // header of the email to be sent out.
    os.writeBytes("DATA\r\n");
    os.writeBytes("X-Mailer: Via Java\r\n");
    os.writeBytes("DATE: " + dFormat.format(dDate) + "\r\n");
    System.out.println("DATE: " + dFormat.format(dDate) + "\r\n");
    os.writeBytes("From: Me <[email protected]>\r\n");
    os.writeBytes("To: YOU <[email protected]>\r\n");
    //Again if you want to send a CC then add this.
    //os.writeBytes("Cc: CCDUDE <[email protected]>\r\n");
    //Here you can now add a BCC to the message as well
    //os.writeBytes("RCPT Bcc: BCCDude<[email protected]>\r\n");
    String sMessage = "Your subjectline here";
    os.writeBytes("Subject: Your subjectline here\r\n");
    os.writeBytes(sMessage + "\r\n");
    os.writeBytes("\r\n.\r\n");
    os.writeBytes("QUIT\r\n");
    // Now send the email off and check the server reply.
    // Was an OK is reached you are complete.
    String responseline;
    while((responseline = is.readLine())!=null)
    {   System.out.println(responseline);
    if(responseline.indexOf("Ok") != -1)
    break;
    } catch (IOException e) {
    e.printStackTrace();
    It is compiling and runnung properly. Please Help me on this.
    Thanks.
    Satya.

    You're mishandling the responses. You terminate if you don't get an "Ok" string, but that's not how success is defined - you should get a 200 code back, typically with an "OK" (not caps) message.
    It doesn't help that you're ignoring all of the server output after each command, so you never find out if anything goes wrong.
    You're also reinventing a wheel. The JavaMail API exists for this: http://java.sun.com/products/javamail/

  • Java code to create a new .txt file in FTP server  --- Help

    Hi,
    I wrote a standalone java app which creates a .txt file in my local machine and transfers it to FTP server. But my requirement now is to create a new .txt file with the same content in FTP server itself instead of creating locally with basic java code.
    I'm aware of transfering file from local machine to the FTP server using STOR command of FTP. But i never tried creating a new file & writing content into that in FTP server.
    So, if any one did this before please help me out with source code or any idea ???
    Thank you.
    Vj.

    simply_vijay wrote:
    thanks for your reply. yes i've seen the Apache Commons NET API , but there is no method or class to create a new file in FTP server. I'm really worried how to solve this problem ???Sure there is.
    There's a method where you can write data to a file on the server using an OutputStream, right? Well, instead of writing to a FileOutputStream, write to that OutputStream instead. Remember to close the OutputStream and call the method which says you're finished with the command (I forget what it's called).

  • Please help me transform this C++ code to java code....

    guys...please help me transform this C++ code to java code....please try to explain the code..thanks
    [program]
    #include <stdio.h>
    #define ALIVE 1
    #define DEAD 0
    #define SZ 33
    int stschk (int ,int );
    main()
    int s[SZ][SZ], i, j;
    for (i=0; i<sz; i++ ) s[0] = DEAD;
    for (j=0; j<sz; j++ ) s[0][j] = DEAD;
    s[0][1] = ALIVE;
    for (i=0; i<sz-1; i++) {
    for ( j=1;j<sz;j++ ) {
    s[i][j] = stschk(s[i][j-1],s[i+1][j];
    if(s[i][j-1]==ALIVE) printf("*");
    else printf(" ");
    printf("\n");
    int stschk(int s1,int s2)
    if(((s1==DEAD)&&(s2==ALIVE))||
    ((s1==ALIVE)&&(s2==DEAD))) return ALIVE;
    else return DEAD;

    Being picky, that's not C++, that's C. Standard headers in C++ dont' have .h after them, loop variables are scoped with the for, you use constants rather than #defines, etc..
    C and C++ both don't initialise arrays by default; you'd have to write an initialiser to get it to zero out the array:
        int s[sz][sz] = {};gcc will insert a call to memset to zero the array.
    If the author was assuming that the array was zeroed out, there would be no point zeroing the first row and column.
    The code reads values which haven't been initialised. If you mark such values explicitly undefined, and change the program to report an error when undefined, then you get several cases where the program makes such report.
    So either it' s a primitive random number generator (some random number generators use uninitialised memory as a source of randomness), or it's buggy, or it's processing undefined data and throwing away the result. Either way, it cannot be directly be ported to Java if the undefined values (which are limited to a small area of the ouput) are significant.

  • Help in translating JAVA code into CF

    Hi all!  I'm at the end of integrating an in-house calendar with Google calendars and all is working, however, I am stumped as to how implement callback functions.  Here's what I'm trying to do as outlined on http://code.google.com/p/google-api-java-client/source/browse/Batch.wiki?repo=wiki
    What I need to do is this section right here:
    JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() {
      public void onSuccess(Calendar calendar, HttpHeaders responseHeaders) {
        printCalendar(calendar);
        addedCalendarsUsingBatch.add(calendar);
      public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
        System.out.println("Error Message: " + e.getMessage());
    And then later pass it to:
    client.calendars().insert(entry1).queue(batch, callback);
    I believe I can pass one function by passing just the name of the function, but BatchCallback has two functions.  Is this impossible to do in CF?
    Thanks,
    Ross.

    1. In the future, please use a meaningful subject line, like "loop not performing last iteration." Just saying "Help in my java code" is useless. We know you need help with your Java code, else you wouldn't be posting here.
    2. Repost your code without those annoying superfluous asterisks, and with proper indentation in the section that they are currently polluting. It's too hard to read as-is.

  • Run chm help file through java code

    hello,
    would you tell me how can i run a help.chm file using java code. i am trign this but no luck.
    first try
    Process pp=run.exec("C:/Program Files/Internet Explorer/IEXPLORE.exe ./res/bobftphelp.chm" );
    Second try
              Process pp=run.exec(" ./res/bobftphelp.chm" );
    It run fine a help.doc file but not help.chm file.
    please help me
    Thanka in advance
    Ravi Charan

    The second address given to that function, does it relate to the class that its being called from? cause i've got
    Runtime.getRuntime().exec("C:\\WINDOWS\\hh.exe .\\HelpFile_9_3.chm" );where HelpFile_9_3 is in the same folder as my class, but it won't work. Can anyone help?
    Also, can you search within a chm file from Java? If I get that above code working, I presume it'll open the help file to the main page. I'd like to search within that document for a word or phrase - possible?
    Thanks!
    Edited by: Pulkse.co.uk on Sep 10, 2008 8:18 AM

  • Help in my java code?

    below is my code:
    import java.lang.String;
    import java.io.*;
    import java.util.*;
    public class DNASequence{
    public static void main(String args[])throws IOException{
      BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
      String sequenceAn = "ggctggacta ttgagatgcg ggaagagctg cagactccgg tggataaact atttgagacc cgatatcaag agaggaaact tcacaagaga agaagaggaa gctatcatta agttgcatga aatgctgggt aacaggtggt cagcaattgc agcaagatta ccaggacgca cagacaacga gataaaaaat gtatggcaca cccacttgaa gaag";
      String sequence = "DNA";
      String origin = "Prunus persica (peach)";
      String uppercase = sequenceAn.toUpperCase();
      int count = 0;
        for (int i = 0; i < sequenceAn.length(); i++) {
            char c = sequenceAn.charAt(i);
            if (c=='T' || c=='C' || c=='G' || c=='A' || c=='t' || c=='c' || c=='g' || c=='a') {
            count++;
        System.out.println("Sequence: " + sequence);
        System.out.println("Sequence length (nt): " + " " + count + "nt");
        *int counter = 1;*
    *//find how many times to substring*
    *int num = (int)Math.round(sequenceAn.length()/66);*
    *int firstParam = 0;*
    *int secondParam = 66;*
    *for (int i = 0; i < num; i++) {*
    *System.out.print(counter + " ");*
    *System.out.println(sequenceAn.substring(firstParam,secondParam)); //print from index 0 to index 64 = 65chars*
    *firstParam = firstParam + 66;*
    *secondParam = secondParam + 66;*
    *counter = counter + 60;*
        //System.out.println("Sequence annotation :" + uppercase);
        System.out.println("Organism origin :" + origin);
    }output is below:
    Sequence: DNA
    Sequence length (nt): 214nt
    *1 ggctggacta ttgagatgcg ggaagagctg cagactccgg tggataaact atttgagacc*
    *61 cgatatcaag agaggaaact tcacaagaga agaagaggaa gctatcatta agttgcatga*
    *121 aatgctgggt aacaggtggt cagcaattgc agcaagatta ccaggacgca cagacaacga*
    Organism origin :Prunus persica (peach)
    my problem now is it should be like this
    Sequence: DNA
    Sequence length (nt): 214nt
    *1 ggctggacta ttgagatgcg ggaagagctg cagactccgg tggataaact atttgagacc*
    *61 cgatatcaag agaggaaact tcacaagaga agaagaggaa gctatcatta agttgcatga*
    *121 aatgctgggt aacaggtggt cagcaattgc agcaagatta ccaggacgca cagacaacga*
    *181 gataaaaaat gtatggcaca cccacttgaa gaag*
    Organism origin :Prunus persica (peach)
    my another line is not display. please help me. thanks
    Edited by: williamku87_1 on Apr 6, 2010 10:56 AM
    Edited by: williamku87_1 on Apr 6, 2010 10:57 AM

    1. In the future, please use a meaningful subject line, like "loop not performing last iteration." Just saying "Help in my java code" is useless. We know you need help with your Java code, else you wouldn't be posting here.
    2. Repost your code without those annoying superfluous asterisks, and with proper indentation in the section that they are currently polluting. It's too hard to read as-is.

  • Please help me in compiling the enclosed java code

    Iam trying to compile the below mentioned java code and iam getting this error: I have Weblogic 6.1 + sp2 installed on my machine. Please help !
    The error is :
    C:\bea\jdk131>javac Browser.java
    Browser.java:17: cannot resolve symbol
    symbol : class JIconButton
    location: class Browser
    private JIconButton homeButton;
    ^
    Browser.java:25: cannot resolve symbol
    symbol : class ExitListener
    location: class Browser
    addWindowListener(new ExitListener());
    ^
    Browser.java:26: cannot resolve symbol
    symbol : variable WindowUtilities
    location: class Browser
    WindowUtilities.setNativeLookAndFeel();
    ^
    Browser.java:30: cannot resolve symbol
    symbol : class JIconButton
    location: class Browser
    homeButton = new JIconButton("home.gif");
    ^
    4 errors
    THE CODE IS HERE :
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    public class Browser extends JFrame implements HyperlinkListener,
    ActionListener {
    public static void main(String[] args) {
    if (args.length == 0)
    new Browser("http://www.apl.jhu.edu/~hall/");
    else
    new Browser(args[0]);
    private JIconButton homeButton;
    private JTextField urlField;
    private JEditorPane htmlPane;
    private String initialURL;
    public Browser(String initialURL) {
    super("Simple Swing Browser");
    this.initialURL = initialURL;
    addWindowListener(new ExitListener());
    WindowUtilities.setNativeLookAndFeel();
    JPanel topPanel = new JPanel();
    topPanel.setBackground(Color.lightGray);
    homeButton = new JIconButton("home.gif");
    homeButton.addActionListener(this);
    JLabel urlLabel = new JLabel("URL:");
    urlField = new JTextField(30);
    urlField.setText(initialURL);
    urlField.addActionListener(this);
    topPanel.add(homeButton);
    topPanel.add(urlLabel);
    topPanel.add(urlField);
    getContentPane().add(topPanel, BorderLayout.NORTH);
    try {
    htmlPane = new JEditorPane(initialURL);
    htmlPane.setEditable(false);
    htmlPane.addHyperlinkListener(this);
    JScrollPane scrollPane = new JScrollPane(htmlPane);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    } catch(IOException ioe) {
    warnUser("Can't build HTML pane for " + initialURL
    + ": " + ioe);
    Dimension screenSize = getToolkit().getScreenSize();
    int width = screenSize.width * 8 / 10;
    int height = screenSize.height * 8 / 10;
    setBounds(width/8, height/8, width, height);
    setVisible(true);
    public void actionPerformed(ActionEvent event) {
    String url;
    if (event.getSource() == urlField)
    url = urlField.getText();
    else // Clicked "home" button instead of entering URL
    url = initialURL;
    try {
    htmlPane.setPage(new URL(url));
    urlField.setText(url);
    } catch(IOException ioe) {
    warnUser("Can't follow link to " + url + ": " + ioe);
    public void hyperlinkUpdate(HyperlinkEvent event) {
    if (event.getEventType() ==
    HyperlinkEvent.EventType.ACTIVATED) {
    try {
    htmlPane.setPage(event.getURL());
    urlField.setText(event.getURL().toExternalForm());
    } catch(IOException ioe) {
    warnUser("Can't follow link to "
    + event.getURL().toExternalForm() + ": " + ioe);
    private void warnUser(String message) {
    JOptionPane.showMessageDialog(this, message, "Error",
    JOptionPane.ERROR_MESSAGE);

    I got this code from this forum concerning MONITORING some application. Iam working on writing something which can monitor the availabilty of my application on the browser. Iam not familiar with swings so i got confused with compiling this code.
    Please let me know if you know some code that can help me monitor my web based application.
    Thanks in advance.

  • Who can help me write this Java code show the prime number ???? PLEASEEEEEE

    Write java code print prime number like this
    Sample Screen Print:
    Initial matrix with N = 37
    2 3 4 5 6 7 8 9 10
    11 12 13 14 15 16 17 18 19 20
    21 22 23 24 25 26 27 28 29 30
    31 32 33 34 35 36 37
    Intermediate results (after 1st iteration)
    2 3 5 7 9
    11 13 15 17 19
    21 23 25 27 29
    31 33 35 37
    Intermediate results (after 2nd iteration)
    2 3 5 7
    11 13 17 19
    23 25 29
    31 35 37
    Intermediate results (after 7th iteration)
    2 3 5 7
    11 13 17 19
    23 29
    31 37
    Final results
    2 3 5 7 11 13 17 19 23 29
    31 37
    How to write this code ?
    Please Help me!
    Thank you so muchhh ?????

    h2. {color:#ff0000}Multiplepost{color}
    Replies here: http://forum.java.sun.com/thread.jspa?threadID=5241012&tstart=0
    There is a useful answer the original thread. Answer it, or ignore it as you like, but don't create multiple threads.

Maybe you are looking for

  • Upgrade T61 6457-CTO to Windows 7 (64 bit)?

    HI, I have a T61  6457-CTO running windows XP pro.  After 2 years of multiple versions of office & Adobe Creative Suite as well as other software, it is now very sluggish.  Since I am getting new office & Adobe software I thought I might I upgrade to

  • AS3 moving clips in array not working

    I'm having three movie clips, which I would like to move randomly within a set box. The following script works with one movie, but not with all movies placed in an array. Please help! var clipSpeed:Number= 1; var speedX:Number = 0 var speedY:Number =

  • [stupid]error: cannot resolve "libusb1", a dependency of "libdc1394"

    Hi! :: Starting full system upgrade... resolving dependencies... error: cannot resolve "libusb1", a dependency of "libdc1394" error: failed to prepare transaction (could not satisfy dependencies) :: libdc1394: requires libusb1 I needed libdc1394 only

  • Can't share screen with my other Mac

    I loaded Leopard on both of my intel macs...a mini and a macbook. When I try to share a screen it ask me for my password and then tells me its wrong..Can anyone help? Thanks Perry

  • Lens Correction Batch Application Not Working

    Using LR3, I can set the lens correction then go to 'Develop Settings/Copy Settings' and the option is there for lens correction (I check all of the boxes under lens correction).  If I paste the settings to just one photo, the lens correction applies