swings

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;
}
 
A

Andrew Thompson

Sub: 'swings'

Note that the GUI toolkit you are referring to is 'Swing'
(starts with a capital letter - no 's' on the end).

Further 'swings' is a poor title.

I suggest 'background image for Swing panel'
might have been better at getting the attention
of those that might be able to help.

vijji wrote:
....
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.

I am not able to compile that mess of code you posted*
(was it written by you, or your chicken?), however I can
offer a single peice of generic advice.
public class PaneExample extends JFrame {

For Swing components, ..
public void paint(Graphics g) {

...override paintComponent(), rather than paint().

* Problems where compilable code is supplied, are
more likely to get solved.

The code you posted was missing brackets, and
would not compile because of that - further, it was
inconsistently indented, so it was hard to tell what
you meant.

After reformatting the code and inserting the missing
brackets - I got to discover that it referred to a class
that is not in the J2SE - and not included in your post.

...That's it - I'm outta' here!

I suggest in future to post an SSCCE* instead
of these code snippets
* <http://www.physci.org/codes/sscce/>

Andrew T.
 
T

Thomas Kellerer

Andrew Thompson wrote on 19.09.2006 10:53:
Note that the GUI toolkit you are referring to is 'Swing'
(starts with a capital letter - no 's' on the end).
I do see "Swing" beeing referenced as "swings" a lot, wonder where that comes
from...

Thomas
 
A

Andrew Thompson

Thomas said:
Andrew Thompson wrote on 19.09.2006 10:53:
I do see "Swing" beeing referenced as "swings" a lot, wonder where that comes
from...

I cannot say I have noticed it much, but if the places that
it occurs are in posts with a lot of 'SMSese', I probably
stopped reading at the second sentence and missed it.

Andrew T.
 
B

Babu Kalakrishnan

Thomas said:
Andrew Thompson wrote on 19.09.2006 10:53:

I do see "Swing" beeing referenced as "swings" a lot, wonder where that
comes from...

My guess is that its origin could be some popular group of Computer
training institutes in India (who probably circulate their study
materials to different branches across the country). Out of some 20
people I interviewed last week for a position, at least 4 or 5 claimed
expertise in "swings" - and not all of them were from the same city
either :)

BK
 
T

Thomas Weidenfeller

Babu said:
My guess is that its origin could be some popular group of Computer
training institutes in India (who probably circulate their study
materials to different branches across the country). Out of some 20
people I interviewed last week for a position, at least 4 or 5 claimed
expertise in "swings" - and not all of them were from the same city
either :)

I thought there might be one of these stupid "Java interview question
collections" out there with that mistake. And that cheaters don't spot
the mistake because they don't know Swing.

Googling^1 for "+Java +swings -swing" didn't reveal any particular
culprit, but quite some 325000 hits, many of them job advertisings or CVs.

/Thomas

1. If I suddenly disappear, Google lawyers got me because of using that
word.
 
A

Andrew Thompson

Thomas Weidenfeller wrote:
.....
Googling^1 for "+Java +swings -swing" didn't reveal any particular
culprit, but quite some 325000 hits, many of them job advertisings or CVs. ...
1. If I suddenly disappear, Google lawyers got me because of using that
word.

LOL!

I say - a googleplex of Googling to those Googlawyers.

Andrew T.
 
C

Chris Uppal

Babu said:
My guess is that its origin could be some popular group of Computer
training institutes in India

I wonder (drifting inexorably off-topic) if maybe the English word "swing" is
awkward for speakers of one or another Indian language -- like the way that (as
I understand it) foreign words which don't end with a vowel are uncomfortable
for Japanese speakers -- if so, then maybe the trailing 's' makes the word more
palatable (pun intended).

-- chris
 
B

Babu Kalakrishnan

Chris said:
Babu Kalakrishnan wrote:




I wonder (drifting inexorably off-topic) if maybe the English word "swing" is
awkward for speakers of one or another Indian language -- like the way that (as
I understand it) foreign words which don't end with a vowel are uncomfortable
for Japanese speakers -- if so, then maybe the trailing 's' makes the word more
palatable (pun intended).

Pretty unlikely - If that were the case I'd have expected to have heard
the term very often much earlier. This somehow seems like a fairly
recent phenomenon. (And swing has been around a pretty long time)

On hindsight, I feel I should have asked those guys/gals as to where
they learnt their "swings" from - may be next time :)

BK
 
C

Chris Uppal

Babu Kalakrishnan wrote:

[me:]
Pretty unlikely - If that were the case I'd have expected to have heard
the term very often much earlier. This somehow seems like a fairly
recent phenomenon. (And swing has been around a pretty long time)

Sigh...

I'm sure you're right, but it was such a pretty idea...

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top