|
![]() |
#1 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() 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); *********/ **************** **************** ****} } 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..." ![]() |
||
![]() ![]() |
|
![]() |
#2 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Feb 2007
Location: Brooklyn, United States
Posts: 667
|
![]() 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 |
||
![]() ![]() |
|
![]() |
#3 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() I discovered a problem. A path to file with my picture was incorrect.
__________________
"Paladin work is never done..." ![]() |
||
![]() ![]() |
|
![]() |
|
![]() |
||||
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 |
|
|
||
  |