Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [JAVA] - apertura finestrella



    come posso fare in modo che l'apertura della finestrella piccola sia sempre in quella posizione?

    spiego meglio:
    ora ho fatto in modo che l'apertura della finestrella piccola sia sempre allineata con quella grande nel modo visto in figura.

    ma se sposto la finestra grande + in basso o in alto o a dx o a sx la finestrella piccola rimane sempre li in quanto ho dato come location quella posizione esatta.

    ho provato vari modi ma nn riesco a farla aprire allineata indipendentemente dalla posizione della calcolatrice

  2. #2
    dimenticavo:

    l'inizio del codice che crea la finstra grande:
    codice:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class calc
    {
    	public static void main(String[] args)
    	{
    		JFrame.setDefaultLookAndFeelDecorated(true);
    		JFrame f = new JFrame("Calcolatrice");
    		f.setLocation(250,120);


    quello che crea la finestra piccola:

    codice:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class Autori extends JFrame
    {
    	private String nome;
    
    	public Autori(String n, int i)
    	{
    		nome = n;
    		
    		JFrame.setDefaultLookAndFeelDecorated(true);
    		JFrame f = new JFrame("Autori");
    		f.setLocation(570, 120);

  3. #3
    ho trovato questo metodo nelle api:

    public void setLocationRelativeTo(Component c)


    Sets the location of the window relative to the specified component. If the component is not currently showing, or c is null, the window is centered on the screen. If the bottom of the component is offscreen, the window is placed to the side of the Component that is closest to the center of the screen. So if the Component is on the right part of the screen, the Window is placed to its left, and visa versa.

    Parameters:
    c - the component in relation to which the window's location is determined
    Since:
    1.4
    cosa devo usare come "Component c"?
    Il nome dato al Frame della finestra grande?

  4. #4
    se dovesse servire a qualcuno ho risolto in questo modo:
    calc è la classe che contiene la finestra più grande in cui ho scritto un metodo posizione() in questo modo:
    codice:
    public static Point posizione()
    {
         return f.getLocationOnScreen();
    }
    codice:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class Autori extends JFrame
    {
    	private static String nome;
    
    	private static JFrame f;
    
    	public Autori(String n, int i)
    	{
    		nome = n;
    		
    		JFrame.setDefaultLookAndFeelDecorated(true);
    		f = new JFrame("Autori");
    		
    		Point puntoiniziale = calc.posizione();
    		int xCoord = (int) puntoiniziale.getX();
    		int yCoord = (int) puntoiniziale.getY();
    		f.setLocation(xCoord+320,yCoord);
    ovviamente 320 è la grandeza in pixel della finestra grande (310px) + 10px per il suo bordo

    bye

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.