V
vijji
Hi,
I am working on swings as a desktop application.
How to implement jpanel on background images of a JFrame?
I am not able to get the panel if i got the image and
i am not able to get image if I got the panel.
import javax.swing.*;
import java.awt.*;
import java.awt.Image;
public class PaneExample extends JFrame {
static Image img,_image;
public PaneExample() {
super("Login");
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel opaque = createNested(true);
Image img=Toolkit.getDefaultToolkit().getImage("g.gif");;
getContentPane().setLayout(new
FlowLayout(FlowLayout.CENTER,300,400));
getContentPane().add(opaque);
}
public void paint(Graphics g) {
if(img!= null) {
int x = 0, y = 0;
while(y < img.getHeight(null)) {
x = 0;
while(x< getSize().width) {
g.drawImage(img, x, y, this);
x= x + img.getWidth(null);
}
y = y + img.getHeight(null);
}
g.setFont(new Font("Helvetica", Font.PLAIN,
40));
g.drawImage(img,10,10,this);
}else {
g.clearRect(0, 0, getSize().width,
getSize().height);
}
public static void main(String[] args) {
PaneExample oe = new PaneExample();
Graphics2D01 guiObj = new Graphics2D01();
int wid=guiObj.getWidth();
int height=guiObj.getHeight();
System.out.println(wid + "" + height);
oe.setSize(wid,height);
oe.setVisible(true);
}
public JPanel createNested(boolean opaque) {
JPanel outer = new JPanel(new FlowLayout());
JLabel l1 = new JLabel("User Name");
outer.add(l1);
JTextField tf1= new JTextField(10);
outer.add(tf1);
JLabel l2 = new JLabel("password");
outer.add(l2);
JTextField tf2= new JTextField(10);
outer.add(tf2);
JButton b1 = new JButton("Login");
outer.add(b1);
outer.setPreferredSize(new Dimension(200, 100));
outer.setBackground(Color.blue);
return outer;
}
I am working on swings as a desktop application.
How to implement jpanel on background images of a JFrame?
I am not able to get the panel if i got the image and
i am not able to get image if I got the panel.
import javax.swing.*;
import java.awt.*;
import java.awt.Image;
public class PaneExample extends JFrame {
static Image img,_image;
public PaneExample() {
super("Login");
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel opaque = createNested(true);
Image img=Toolkit.getDefaultToolkit().getImage("g.gif");;
getContentPane().setLayout(new
FlowLayout(FlowLayout.CENTER,300,400));
getContentPane().add(opaque);
}
public void paint(Graphics g) {
if(img!= null) {
int x = 0, y = 0;
while(y < img.getHeight(null)) {
x = 0;
while(x< getSize().width) {
g.drawImage(img, x, y, this);
x= x + img.getWidth(null);
}
y = y + img.getHeight(null);
}
g.setFont(new Font("Helvetica", Font.PLAIN,
40));
g.drawImage(img,10,10,this);
}else {
g.clearRect(0, 0, getSize().width,
getSize().height);
}
public static void main(String[] args) {
PaneExample oe = new PaneExample();
Graphics2D01 guiObj = new Graphics2D01();
int wid=guiObj.getWidth();
int height=guiObj.getHeight();
System.out.println(wid + "" + height);
oe.setSize(wid,height);
oe.setVisible(true);
}
public JPanel createNested(boolean opaque) {
JPanel outer = new JPanel(new FlowLayout());
JLabel l1 = new JLabel("User Name");
outer.add(l1);
JTextField tf1= new JTextField(10);
outer.add(tf1);
JLabel l2 = new JLabel("password");
outer.add(l2);
JTextField tf2= new JTextField(10);
outer.add(tf2);
JButton b1 = new JButton("Login");
outer.add(b1);
outer.setPreferredSize(new Dimension(200, 100));
outer.setBackground(Color.blue);
return outer;
}