!_NEWLINE_!I'm making a Swing Application and have some problem...
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, March 15, 2001 03:48 AM

I'm making a Swing Application and have some problem with that for design (set skinning like Winamp) I get some problem with that. for making JFrame which doesn't have a title bar but does all things (moving, resizing ....) like that. So I decied use JWindow, set drag zone on it, lay two text field on JWindow. The JWindow occured some problem with it's funciton 1. Cursor has disappear when I clicked JTextField area. 2. When JWindow get focus after loosing focus, JTextField couldn't edit & delete the character 3. When dragged JWindow, the JWindow does't move well (more than 2 JWindow instancate activated) Sorry about my poor english... Please Help Me    More>>
			
I'm making a Swing Application and have some problem with that for design (set skinning like Winamp)

I get some problem with that.
for making JFrame which doesn't have a title bar but does all things (moving, resizing ....) like that.
So I decied use JWindow, set drag zone on it, lay two text field on JWindow.

The JWindow occured some problem with it's funciton

1. Cursor has disappear when I clicked JTextField area.
2. When JWindow get focus after loosing focus, JTextField couldn't edit & delete the character
3. When dragged JWindow, the JWindow does't move well
(more than 2 JWindow instancate activated)

Sorry about my poor english...
Please Help Me

The Source is *******************************

import java.awt.event.* ;
import javax.swing.* ;
import javax.swing.JWindow.* ;
import java.awt.* ;
import javax.swing.plaf.* ;


public class TestMain extends JWindow implements ActionListener, MouseListener, MouseMotionListener {

private JTextField jtf_id = null ;
private JTextField jtf_passwd = null ;
private JLabel jlb_dragpoint = null ;
private JButton jbtn_window = null ;
private JButton jbtn_close = null ;
private JButton jbtn_exit = null ;

public TestMain() {
Font font = new Font("Sanserif", Font.PLAIN, 14) ;
// Drag Point
JPanel headerPanel = new JPanel() ;
headerPanel.setOpaque(false) ;
jlb_dragpoint = new JLabel("DragPoint") ;
jlb_dragpoint.setOpaque(false) ;
jlb_dragpoint.addMouseMotionListener(this) ;
jlb_dragpoint.addMouseListener(this) ;
headerPanel.add(jlb_dragpoint) ;

// Body Part
JPanel bodyPanel = new JPanel() ;
bodyPanel.setOpaque(false) ;
JLabel jlb_id = new JLabel("ID") ;
jlb_id.setOpaque(false) ;
JLabel jlb_passwd = new JLabel("Password") ;
jlb_passwd.setOpaque(false) ;
jlb_id.setHorizontalAlignment(JLabel.RIGHT) ;
jlb_passwd.setHorizontalAlignment(JLabel.RIGHT) ;
jlb_id.setFont(font) ;
jlb_passwd.setFont(font) ;

jtf_id = new JTextField() ;
jtf_passwd = new JTextField() ;

bodyPanel.setLayout(new GridLayout(2, 2)) ;
bodyPanel.add(jlb_id) ;
bodyPanel.add(jtf_id) ;
bodyPanel.add(jlb_passwd) ;
bodyPanel.add(jtf_passwd) ;

// Tail Part
JPanel tailPanel = new JPanel() ;
tailPanel.setOpaque(false) ;
jbtn_window = new JButton("Open") ;
jbtn_window.addActionListener(this) ;
jbtn_close = new JButton("Close") ;
jbtn_close.addActionListener(this) ;
jbtn_exit = new JButton("Exit") ;
jbtn_exit.addActionListener(this) ;

tailPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)) ;
tailPanel.add(jbtn_window) ;
tailPanel.add(jbtn_close) ;
tailPanel.add(jbtn_exit) ;


getContentPane().add(headerPanel, "North") ;
getContentPane().add(bodyPanel, "Center") ;
getContentPane().add(tailPanel, "South") ;

this.setSize(250, 150) ;
this.setLocation(100, 100) ;
this.show() ;
}

private Point eventPosition = null ;
protected Dimension screenSize = null ;

public void mouseDragged(MouseEvent e) {
if (e.getSource() == jlb_dragpoint) {
int x = this.getX() + e.getX() - eventPosition.x ;
int y = this.getY() + e.getY() - eventPosition.y ;

if (x < 0) x = 0 ;
if (x > (screenSize.width - this.getWidth())) x = screenSize.width - this.getWidth() ;

if (y < 0) y = 0 ;
if (y > (screenSize.height - this.getHeight())) y = screenSize.height - this.getHeight() ;

this.setLocation(new Point(x, y)) ;
}
}


// Event Definition !!
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jbtn_window) {
TestMain tm_sub = new TestMain() ;
Point parentPosition = this.getLocation() ;
tm_sub.setLocation(parentPosition.x + 20 , parentPosition.y + 20 ) ;
}

if (e.getSource() == jbtn_close) {
this.dispose() ;
}

if (e.getSource() == jbtn_exit) {
System.exit(0) ;
}
}

public void mouseMoved(MouseEvent e) {}

public void mousePressed(MouseEvent e) {
if (e.getSource() == jlb_dragpoint) {
if (screenSize == null) screenSize = Toolkit.getDefaultToolkit().getScreenSize() ;
eventPosition = new Point(e.getX(), e.getY()) ;
}
}

public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}


// Main Event...
public static void main(String args[]) {
new TestMain() ;
}
}
   <<Less
About | Sitemap | Contact