Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 22-03-2007, 06:01 PM   #1
Nick
Переводчик помаленьку
 
Nick's Avatar

 
Join Date: Dec 2004
Location: Protvino, Russian Federation
Posts: 340
Send a message via ICQ to Nick Send a message via Skype™ to Nick
Default

Here's my sources.

Code:
package main;

import java.awt.*;

public class Main
{ 

****/**
**** * @param args
**** */
********
****public static void main(String[] args) 
****{
********Frame fr = new Window(640, 480, "My Window");
********fr.setVisible(true);
************************
********Button b = new Button("Test");
********b.setSize(100, 20);
********b.setLocation(0, 50);
********fr.add(b);
********
********/*
********Button b = new Button("Test");
********b.setSize(100, 20);
********b.setLocation(0, 30);
********fr.add(b);
*********/
****************
****************
****}

}
And the Window class:

Code:
package main;

import java.awt.*;
import java.awt.event.*;

public class Window extends Frame
{

****/**
**** * 
**** */
****
****Image image;

****public Window(int x, int y, String name)
****{
********setSize(640, 480);
********setVisible(true);
********setTitle(name);
********
********addWindowListener (new WindowAdapter()****
************{
****************public void windowClosing(WindowEvent ev)
****************{
********************System.exit (0);
****************}****
************}
********);
********
********setLayout(null);
****}
****
****public void paint(Graphics g)
****{********
********Image im = getToolkit().getImage("Sprites/Character/idle.bmp");
********g.drawImage(im, 0, 0, null);
****************
********g.setFont(new Font("Serif", Font.ITALIC | Font.BOLD, 30)); 
********g.drawString("Hello, XXI century World!", 20, 100);**
****}
****

}
__________________
"Paladin work is never done..."


Nick is offline                         Send a private message to Nick
Reply With Quote
Old 22-03-2007, 07:47 PM   #2
Geezer
Abandonia Homie
 
Geezer's Avatar

 
Join Date: Feb 2007
Location: Brooklyn, United States
Posts: 667
Default

Here is a utility class that i put together to paint background images on JPanels with the option of painting a slogan/title in each panel.



Code:
 

import javax.swing.*;
import java.awt.*;
import java.net.*;

 

/** Background is a utility that creates a panel with a background image and 
 * a slogan. With the first contructor, the size of the panel, the location of 
 * the image and the color of the slogan are passed as parameters. Another constructor
 * creates a solid color background (no image) with the size of the panel, the 
 * background color and slogan color as parameters.**/ 

 

public class Background extends JPanel
{
 String banner;
 String slogan;
 String imageLocation;
 ImageIcon logoIcon;
 Image logoImage;
 URL imageURL;
 Font logoFont;
 int offsetX;
 int offsetY;
 
 public Background(int backgroundWidth, int backgroundHeight, String imageLocation,
 Color fontColor, String banner, String slogan, Font logoFont, int offsetX, int offsetY)
 {
**this.imageLocation = imageLocation;
**this.banner = banner;
**this.slogan = slogan;
**this.logoFont = logoFont;
**this.offsetX = offsetX;
**this.offsetY = offsetY;**
**
**Dimension backgroundDimension = new Dimension(backgroundWidth, backgroundHeight);
**setPreferredSize(backgroundDimension);
**setForeground(fontColor);
**setFont(logoFont);**
**setOpaque(true);
 }
 
 public Background(int backgroundWidth, int backgroundHeight, Color fontColor,
 Color backColor, String banner, String slogan, Font logoFont, int offsetX, int offsetY)
 {
**this.imageLocation = null;
**this.banner = banner;
**this.slogan = slogan;
**this.logoFont = logoFont;
**this.offsetX = offsetX;
**this.offsetY = offsetY;**
****
**Dimension backgroundDimension = new Dimension(backgroundWidth, backgroundHeight);
**setPreferredSize(backgroundDimension);
**setForeground(fontColor);
**setBackground(backColor);
**setFont(logoFont);**
**setOpaque(true);
 }
 
 protected void paintComponent(Graphics g)
 {
**super.paintComponent(g);
**FontMetrics bfm1 = g.getFontMetrics();**
**** 
**if (imageLocation != null)
**{
** Class metaObject = this.getClass();
** imageURL = metaObject.getResource(imageLocation);
** logoIcon = new ImageIcon(imageURL);
** logoImage = logoIcon.getImage();
** if (logoImage != null)
****g.drawImage(logoImage, 0, 0, getWidth(), getHeight(), this);
**}

**if (banner != "")
**{
** int bannerWidth = bfm1.stringWidth(banner);
** int xc1 = getWidth() / 2 - bannerWidth / 2;
** g.drawString(banner, xc1, offsetY);
**}
****
**if (slogan != "")
**{
** int sloganWidth = bfm1.stringWidth(slogan);
** int xc2 = getWidth() / 2 - sloganWidth / 2;
** g.drawString(slogan, xc2, (offsetY + 25));**
**}
**
//**System.out.println("Graphics painted.");
**
 } 
}
__________________
"The gadfly has returned! Thou simpering, whining stable dropping. I have defeated thee repeatedly and still thou darest crawl back for more punishment. Chastise thee I shall. Thy stature is insignificant and thy name moronic. Brother to the vole! Offspring of money grubbing know nothings!" ... Spellcraft: Aspects of Valor
Geezer is offline                         Send a private message to Geezer
Reply With Quote
Old 24-03-2007, 05:39 PM   #3
Nick
Переводчик помаленьку
 
Nick's Avatar

 
Join Date: Dec 2004
Location: Protvino, Russian Federation
Posts: 340
Send a message via ICQ to Nick Send a message via Skype™ to Nick
Default

I discovered a problem. A path to file with my picture was incorrect. Me is LOL.
__________________
"Paladin work is never done..."


Nick is offline                         Send a private message to Nick
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need a Java tutorial... Fubb Programming 12 13-04-2009 10:26 AM
10th Frame Pro Bowling Simulator Romano Games Discussion 3 20-07-2008 02:52 PM
How To Use Java Vm In Windows Xp? The Fifth Horseman Tech Corner 19 27-07-2005 10:29 PM
Java Game Reaperman Programming 3 23-02-2005 02:27 PM
Java Kon-Tiki Tech Corner 50 13-12-2004 12:19 AM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 03:45 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.