Results 1 to 13 of 13
Thread: How to clear JDesktopPane
- 12-10-2008, 05:47 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
How to clear JDesktopPane
Dear friends,
i have a big trouble. I need to clear everything on jDesktopPane.
This is my code
this is my GestInterfaccia.java class: this is a pattern, a sort of frontController that will handle the communication and the path between classes.Java Code:package utilities; import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JDesktopPane; import javax.swing.JLabel; import java.awt.Rectangle; public class Sfondo extends javax.swing.JFrame { public JDesktopPane sfondo = new JDesktopPane(); public JLabel immagineSfondo = new JLabel(); public JLabel immagineAgenda = new JLabel(); public Sfondo() { super(); try { javax.swing.UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); getContentPane().add(sfondo, BorderLayout.CENTER); sfondo.add(immagineSfondo); sfondo.add(immagineAgenda); immagineSfondo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("immagini/sig.gif"))); immagineSfondo.setBounds(new Rectangle(510, 330, 400, 220)); immagineAgenda.setIcon(new ImageIcon(getClass().getClassLoader().getResource("immagini/agenda.png"))); immagineAgenda.setBounds(new Rectangle(0, 310, 315, 225)); sfondo.setForeground(new java.awt.Color(0,128,255)); sfondo.setBackground(new java.awt.Color(113,208,255)); sfondo.setSize(760, 560); } catch(Exception e) { e.printStackTrace(); } } }
this is Login.java class: this is the class that is called by the main method.Java Code:package patterns; import java.awt.BorderLayout; import javax.swing.SwingUtilities; import avvio.Login; import avvio.Registrazione; public class GestInterfaccia { public static void Registrazione(){ new Registrazione(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { Login inst = new Login(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } }
So, my question is:Java Code:package avvio; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import utilita.Sfondo; import javax.swing.WindowConstants; public class Login extends utilita.Sfondo { private static final long serialVersionUID = 6897844918257163716L; private JButton tasto_conferma; private JButton registra; public static JPasswordField campo_password; private JButton reimposta; public static JTextField campo_nome_utente; private JLabel password; private JLabel nome_utente; public Login() { super(); initGUI(); } private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { { nome_utente = new JLabel(); sfondo.add(nome_utente); nome_utente.setText("Nome utente"); ... } { password = new JLabel(); sfondo.add(password); password.setText("Password"); ... } { campo_nome_utente = new JTextField(); sfondo.add(campo_nome_utente); ... } { tasto_conferma = new JButton(); sfondo.add(tasto_conferma); tasto_conferma.setText("Conferma"); tasto_conferma.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { tasto_confermaActionPerformed(evt); } }); } { campo_password = new JPasswordField(); sfondo.add(campo_password); } { registra = new JButton(); sfondo.add(registra); registra.setText("Registrati"); registra.setBounds(482, 277, 63, 22); registra.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { registraActionPerformed(evt); } }); } } pack(); this.setSize(760, 560); } catch (Exception e) { e.printStackTrace(); } } private void registraActionPerformed(ActionEvent evt) { System.out.println("registra.actionPerformed, event="+evt); patterns.GestInterfaccia.Registrazione(); } private void tasto_confermaActionPerformed(ActionEvent evt) { System.out.println("registra.actionPerformed, event="+evt); patterns.Controlli.ConfermaLogin(); } }
When i click on "Registrati" the button calls GestInterfaccia.Registrazione() which calls Registrazione();
How can i clean the background "Sfondo"?
I would like to mantain the container jOptionPane but i would like to "erase" what else is on the screen (like buttons, text fields and labels).
Any help appreciated!!!
Thanks.
- 12-10-2008, 06:05 PM #2
simple way may be to create a default initializer method that does setBackground, setSize, etc for you and have another method that adds your buttons, labels, etc. That way you can just call the init method and "redraw", I guess would be what it's doing, the base layout.
- 12-10-2008, 06:31 PM #3
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
Yes, that's what i need, but... i don't know how to do it. Can you show me an example?
Really big Thanks!!!
- 12-10-2008, 07:17 PM #4
Java Code:public void setInit(JDesktopPane sfondo){ getContentPane().add(sfondo, BorderLayout.CENTER); sfondo.add(immagineSfondo); sfondo.add(immagineAgenda); immagineSfondo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("immagini/sig.gif"))); immagineSfondo.setBounds(new Rectangle(510, 330, 400, 220)); immagineAgenda.setIcon(new ImageIcon(getClass().getClassLoader().getResource("immagini/agenda.png"))); immagineAgenda.setBounds(new Rectangle(0, 310, 315, 225)); sfondo.setForeground(new java.awt.Color(0,128,255)); sfondo.setBackground(new java.awt.Color(113,208,255)); sfondo.setSize(760, 560); }Set your Registrati button to call the blank constructor and setInit() methodJava Code:public void setButtons(JDesktopPane sfondo){ //sfondo.addButton or whatever it is in here }
- 12-10-2008, 08:22 PM #5
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
- 12-10-2008, 08:29 PM #6
in your registraActionPerformed just add setInit() to it
Basically what happens if you create your layout, buttons and all, and once the person clicks the button it calls the setInit() method to redraw everything blank.
- 12-10-2008, 09:42 PM #7
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
- 12-10-2008, 09:50 PM #8
you have to write the setInit() method before you can use it.
public void setInit(){
crap goes here
}
- 12-10-2008, 09:54 PM #9
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
- 12-10-2008, 10:31 PM #10
If your trying to access that method outside the class it's written in you need to do ClassName.setInit(); So when you're calling it from Registrazione it would be Sfondo.setInit()
- 12-10-2008, 11:05 PM #11
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
Errr.... i tried, but i got this error
The method setInit(JDesktopPane) in the type Sfondo is not applicable for the arguments ()
Sorry... but i can't understand. Really. I'm starting to think i'm really dumb.
- 12-10-2008, 11:08 PM #12
your missing the JDesktopPane argument. When you call setInit you need to send sfondo with it. ie, setInit(sfondo); or whatever your JDesktopPane object is called
- 12-10-2008, 11:25 PM #13
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
JDesktopPane demo
By Java Tip in forum javax.swingReplies: 0Last Post: 06-26-2008, 07:43 PM -
How to add SystemTray to JDesktopPane
By elisabethkron@yahoo.co.uk in forum Advanced JavaReplies: 0Last Post: 04-07-2008, 08:37 PM -
clear cache
By Jadellll in forum New To JavaReplies: 0Last Post: 03-20-2008, 09:27 AM -
Help, someone clear up Interfaces for me
By mathias in forum New To JavaReplies: 1Last Post: 08-06-2007, 02:26 AM -
I want to do is clear the console
By paul in forum Advanced JavaReplies: 7Last Post: 08-03-2007, 06:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks