sowmiya_ckr
JAVA
3 Answer(s)      3 years and 11 months ago
Posted in : Java Beginners

sir" HOW TO DISPLAY TEXT FIELD IN A BACKGROUND IMAGE AT THE RUN TIME EITHER USING SWING OR APPLET IN JAVA BUT NOT AS JAVA SCRIPT"

Thanks sowmiya.R

Ads

View Answers

September 5, 2012 at 11:35 AM


Here is a java swing code that displays background image.

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;

public class BackgroundImage{
private BufferedImage image;
private JPanel panel = new JPanel(new GridLayout(4,2)) {
protected void paintComponent(Graphics g){
super.paintComponent(g);
if (image != null){
g.drawImage(image, 0, 0, this);
}
}
};
public BackgroundImage(){
try{
File file=new File("C:\\rose.jpg");
image = ImageIO.read(file);
Dimension imageSize = new Dimension(image.getWidth(), image.getHeight());
panel.setPreferredSize(imageSize);
JLabel label1=new JLabel("Username: ");
JLabel label2=new JLabel("Password: ");
JTextField text1=new JTextField(10);
JTextField text2=new JTextField(10);
JButton b1=new JButton("Login");
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(b1);
}
catch (Exception e){}
}
public JPanel getPanel(){
return panel;
}
public static void main(String[] args) {
JFrame frame = new JFrame("BackgroundImage ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new BackgroundImage().getPanel());
frame.setSize(300,150);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}


September 5, 2012 at 3:48 PM




September 5, 2012 at 8:25 PM


thanks sir










Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
Advertisements
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
Java
Java   Whether Java is pure object oriented Language
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  Does java allows multiline comments

Ads

Advertisement