LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   background images in java applications - HELP (https://www.linuxquestions.org/questions/programming-9/background-images-in-java-applications-help-454540/)

ohfaney 06-13-2006 10:26 PM

background images in java applications - HELP
 
so i want to put a background image in my application, so all my text is on top of it. however, i must be doing something wrong because its not even running. HELPPPPPP.

heres my code

Code:

import java.awt.*;
import java.io.*;
import java.awt.Image;
 

public class ISUPROJECT
{
    public static void main (String[] args)
        throws java.io.IOException
    {
      java.awt.Toolkit.getDefaultToolkit ();


            Image img = Toolkit.getDefaultToolkit ().getImage (gutmann_cord.jpg);
           
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        //Opening Header
        System.out.println ("\t\t\t\tBuild-a-Webpage");

        FileWriter fw = new FileWriter ("textpage.html");
        String input, name, quiz, builder1, builder2, builder3, builder4, builder5, builder6, builder7, builder8, builder9, builder10, builder11, builder12, builder13, builder14;
        int userChoice;

        System.out.print ("\t\t\t\tWhat's your name?: ");
        name = br.readLine ();
        // Prints out the users input
        System.out.println ("\t\t\t\t" + name);
        System.out.println ("\n\n");
        // Saves the users name to the file 'test.txt'
        fw.write (name + "\r\n");


        String menuArray[] = {"A", "B", "C", "D", "E", "F", "H", "I", "J", "K"};
        System.out.println ("Choose a menu option\n");
        System.out.println ("Getting Started A");
        System.out.println ("Learn about html B");
        System.out.println ("Basic Codes C");
        System.out.println ("Tutorials D");
        System.out.println ("Build your own page");
        System.out.println ("\t*Test your skills with color codes H");
        System.out.println ("\t*Make a photo page I");
        System.out.println ("\t*Create a basic page (header, text, one link) J");
        System.out.println ("\t*Create a full working page with background image K");
        System.out.println ("Quiz Yourself F");

        System.out.println ("Your Choice");
        input = br.readLine ();

        if (input.equals (menuArray [0]))
        {
            //getting started page
            System.out.println ("\t\t\t\t\n\nMake a plan\n");
            System.out.println ("\t\t\t\tWhen you're first getting started, it's key to make a plan,\nput down all your thoughts, how the page is supposed to look,\nimages, frames; general page structure.Get a piece of paper,\nand draw out your index page and work out from there.\n\n");

            System.out.println ("\t\t\t\tFind a host\n");
            System.out.println ("\t\t\t\tNaturally you need someone/somewhere to host your page,\nthis is crucial; otherwise no one will see your page other than you on your own PC");
            System.out.println ("\t\t\t\tHosts");
            System.out.println ("\t\t\t\tgeocities.com");
            System.out.println ("\t\t\t\tpiczo.com");
        }
        else if (input.equals (menuArray [1]))
        {
            //history of
            System.out.println ("\t\t\tHTML has had a life-span of roughly seven years. During that time,\n\t\t\t it has evolved from a simple language with a small number of tags to a complex system of mark-up,\n\t\t\t enabling authors to create all-singing-and-dancing Web pages complete\n\t\t\t with animated images, sound and all manner of gimmicks.\n\t\t\t This chapter tells you something about the Web's\n\t\t\t early days, HTML, and about the people, companies and organizations who contributed to HTML+, HTML 2, HTML 3.2 and finally, HTML 4.\n\n");
            System.out.println ("\t\t\tHTML is the language that powers the Web in many respects, as the\n\t\t\t lingua franca that Web browsers are expected to be able to render.\n\t\t\t HTML has had unprecedented levels of success, and the uptake is all\n\t\t\t the more surprising when you realise that it was only invented in 1990,\n\t\t\t and few people knew about it before 1993. In fact, although HTML\n\t\t\t has changed relatively little since those early days, the history of HTML\n\t\t\t is rather cloudy. However, with a little detective work on the Web,\n\t\t\t it is possible to reconstruct most of the events that led to the\n\t\t\t creation and subsequent deployment and acception of HTML.");
            System.out.println ("\t\t\tTim Berners-Lee first started to come up with code for his WWW project\n\t\t\t in 1990. The first mention of him working on code for processing\n\t\t\t HyperText can be found in the original HyperText.m file that Tim worked\n\t\t\t on, dated 25th September 90. From the 27th to the 30th November 1990,\n\t\t\t Tim and Robert Cailliau attended ECHT '90 - the European HyperText Convention. After\n\t\t\t ECHT '90, it appears that he had some more ideas about the\n\t\t\t (probably as yet unnamed) World Wide Web, and in the last few\n\t\t\t months of 1990, he started to produce more code, and also the\n\t\t\t first recorded HTML documents.In fact, the earliest HTML document on the WWW\n\t\t\t at the moment dates from 13th November - a couple of weeks before\n\t\t\t the conference - as evidenced a HTTP HEAD request, which returns");
            System.out.println ("\t\t\tTue, 13 Nov 1990 15:1700 GMT ");
            System.out.println ("\t\t\tThe page is still functional in most modern Web browsers, and even\n\t\t\t contains a functional HyperLink!");
            System.out.println ("\t\t\tSo, what was early HTML actually like? The following is the code used in the oldest HTML document referenced above:-");

            System.out.println ("\t\t\t\t<title>Hypertext Links</title>");
            System.out.println ("\t\t\t\t<h1>Links and Anchors</h1>");
            System.out.println ("\t\t\t\tA link is the connection between one piece of");
            System.out.println ("\t\t\t\t<a href=WhatIs.html>hypertext</a> and another.");

            System.out.println ("These are the tags and attributes evident from the first five days\n\t\t\t of Dec 1990:- Surprisingly enough you can still create a decent webpage\n\t\t\t using only these codes");
        }
        else if (input.equals (menuArray [2]))
        {
            //basic coding information
            System.out.println ("\t\t\t\tBasic Codes\n");
            System.out.println ("\t\t\t\tBold\t<b>TEXT HERE</b>");
            System.out.println ("\t\t\t\tItalic\t<i>TEXT HERE</i>");
            System.out.println ("\t\t\tUnderline\t<u>TEXT HERE</u>");
            System.out.println ("\t\t\tRemember when using these codes that you MUST close the code at the end,\n\t\t\texample; if you're using a 'bold' tag, <b> <--- goes at the beginning,\n\t\t\tand to close it after you've written your text to be bolded\n\t\t\tyou would type </b> <--- to close the tag (the slash MUST be there)\n");



        }
        else if (input.equals (menuArray [3]))
        {
            //tutorials page
            System.out.println ("\t\t\t\tTutorials");

        }
        else if (input.equals (menuArray [5]))
        {
            //quiz goes here
            System.out.println ("\t\t\t\tQuiz");
            System.out.println ("\t\t\tThe following quiz will test your knowledge of HTML\n\n");




        }
        else if (input.equals (menuArray [6]))
        {
            //page builder goes here
            //Header
            System.out.println ("\t\t\t\tBuild your own page\n");
            //Insert 'html' tag
            System.out.println ("Please type your html tag: ");
            builder1 = br.readLine ();
            //Insert 'head' tag
            System.out.println ("Please type your head tag: ");
            builder2 = br.readLine ();
            //Insert '/head' or 'title' tag
            System.out.println ("Please type your title tag, or end your head tag now: ");
            builder3 = br.readLine ();
            //Insert end '/head' tag, or press enter if already done
            System.out.println ("Please enter your closing head tag if you have not already done so, if you have press enter to go onto the next code: ");
            builder4 = br.readLine ();
            //Insert 'body' tag
            System.out.println ("Please enter your beginning body tag: ");
            builder5 = br.readLine ();
            //Insert text color code
            System.out.println ("Enter the color change tag, and a color (ex. blue, red, green, black, grey) and put between the two tags 'hello' (remember this is just a test): ");
            builder6 = br.readLine ();
            //Insert line break code
            System.out.println ("Since we want spaces (or a free line) between each text example, enter a linebreak code now: ");
            builder7 = br.readLine ();
            //Change the size of a font/text
            System.out.println ("Now, enter the font size change code, we want to show an example of how to change the sizing of lettering (adjust the size to whatever you like =]): ");
            builder8 = br.readLine ();
            //Insert line break code
            System.out.println ("Since we want spaces (or a free line) between each text example, enter a linebreak code now: ");
            builder9 = br.readLine ();
            //Font face change
            System.out.println ("To change the font face (or which font we're using, ex. verdana, tahoma, comic sans etc.) enter the font face code, and whatever font you'd like it to be (remember to keep putting text between the opening and closing codes!: ");
            builder10 = br.readLine ();
            //Insert line break code
            System.out.println ("Since we want spaces (or a free line) between each text example, enter a linebreak code now: ");
            builder11 = br.readLine ();
            //Adding it all together in one neat package
            System.out.println ("And finally so you dont have to keep typing all that code, enter the 'whole shebang' font face, color, and size in one (remember words between opening and closing!): ");
            builder12 = br.readLine ();
            //Close body tag
            System.out.println ("Close the body tag: ");
            builder13 = br.readLine ();
            //Close the html tag
            System.out.println ("Close the html tag: ");
            builder14 = br.readLine ();

            System.out.println ("Now you're all done, open your text file (remember it's an html document) in internet explorer (or mozilla), and check out what you did!");
            fw.write (builder1 + "\r\n");
            fw.write (builder2 + "\r\n");
            fw.write (builder3 + "\r\n");
            fw.write (builder4 + "\r\n");
            fw.write (builder5 + "\r\n");
            fw.write (builder6 + "\r\n");
            fw.write (builder7 + "\r\n");
            fw.write (builder8 + "\r\n");
            fw.write (builder9 + "\r\n");
            fw.write (builder10 + "\r\n");
            fw.write (builder11 + "\r\n");
            fw.write (builder12 + "\r\n");
            fw.write (builder13 + "\r\n");
            fw.write (builder14 + "\r\n");


        }
        else if (input.equals (menuArray [7]))
        {
            System.out.println ("Please type your html tag: ");
            builder1 = br.readLine ();
            //Insert 'head' tag
            System.out.println ("Please type your head tag: ");
            builder2 = br.readLine ();
            //Insert '/head' or 'title' tag
            System.out.println ("Please type your title tag, or end your head tag now: ");
            builder3 = br.readLine ();
            //Insert end '/head' tag, or press enter if already done
            System.out.println ("Please enter your closing head tag if you have not already done so, if you have press enter to go onto the next code: ");
            builder4 = br.readLine ();
            //Insert 'body' tag
            System.out.println ("Please enter your beginning body tag: ");
            builder5 = br.readLine ();



        }








        fw.close ();
    } // main method



 





} // ISUPROJECT class

Sorry this is like my 3rd time posting about this, but it's very very urgent and no one has replied! please help, it's driving me mad.

Wim Sturkenboom 06-13-2006 11:47 PM

It does not matter how urgent it is, you simply don't post X times. :tisk: And nothing is urgent here at LQ.

I'm sorry for not replying earlier but some people need to sleep and some people don't know java (I belong in both categories). So just wait till someone who knows java comes along with an answer.

The other threads:
http://www.linuxquestions.org/questi...d.php?t=454488
http://www.linuxquestions.org/questi...d.php?t=454517

ohfaney 06-13-2006 11:59 PM

Quote:

Originally Posted by Wim Sturkenboom
It does not matter how urgent it is, you simply don't post X times. :tisk: And nothing is urgent here at LQ.

I'm sorry for not replying earlier but some people need to sleep and some people don't know java (I belong in both categories). So just wait till someone who knows java comes along with an answer.

The other threads:
http://www.linuxquestions.org/questi...d.php?t=454488
http://www.linuxquestions.org/questi...d.php?t=454517


yeah it's pretty urgent, pretty very urgent because i have to have it finished by 7AM June 14th, and its 12:58AM now. really the only problem i'm having now is that my background is showing up in a seperate applet window outside (and behind) my main program window when running
http://i21.photobucket.com/albums/b2...nic/prtscn.jpg

yeah i print screened it lol.

Mcribs 06-14-2006 03:19 PM

Your System.out.println() calls are printing to the console. To get it to draw on the background image you would need to use the drawString() method in the Graphics class in order for it to draw on the same panel as the background image.

It looks like my advice is too late though but perhaps you could modify your program for good GUI practice through using textfields and drawString() calls.


All times are GMT -5. The time now is 08:25 PM.