praveenmanchu 0 Newbie Poster
import java.awt.*;
import javax.swing.*;
/*
<applet code="JScrollPaneDemo" width=500 height=450>
</applet>
*/
public class JScrollPaneDemo extends JApplet {
/*public JScrollPaneDemo()
{
//repaint();
}*/
 
public void init() {
// Get content pane
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
// Add 400 buttons to a panel
JPanel jp = new JPanel();
jp.setSize(50,50);
jp.setLayout(new GridLayout(3,3));
int b = 0;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
jp.add(new JButton("Button " + b));
++b;
}
}
// Add panel to a scroll pane
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
JScrollPane jsp = new JScrollPane(jp,v,h);
// Add scroll pane to the content pane
contentPane.add(jsp, BorderLayout.CENTER);
}
public void paint(Graphics g)
{
g.drawString("hello",100,50);
}
}

in the above code "hello" is displaying.and after that wherever i rollover my cursor on applet window,at that exact position button is appearing.my doubt is infact,it has to display the 9 buttons when init executed,but the thing happening is--->wherever i rollover cursor at that exact point ,corresponding button is appearing and as the cursor is moving on an applet buttons r appearing,infact i have not written this logic in my program,plz help me y happening so...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.