Calling a method from another class

Status
Nicht offen für weitere Antworten.

JennyK

Mitglied
Ich habe eine probleme und brauche eure hilfe.
ich moechte die addressPanel aus AddressUI.createUI() ins createUI in PartnerUI holen damit ich dort eine dialoge bauen kann. Wie schaffe ich
das?

Danke.

Code:
package client.gui;

import java.awt.*;
import javax.swing.*;

import com.client.application.MainFrame;
import com.client.gui.base.BasicDialogUI;
import com.client.page.base.BasicDialogPage;
import com.client.table.model.AddressModel;


public class AddressUI extends BasicDialogUI{
	/**
	 * 
	 */
	private static final long serialVersionUID = -1214150134433745466L;

	
	public AddressUI(MainFrame frame, BasicDialogPage page) {
		super(frame, page);
	}


	@Override
	
	public void createUI() {
		
	AddressModel am = new AddressModel();
	JTable table = new JTable(am);
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	table.setColumnSelectionAllowed(true);
	JScrollPane scroller = new JScrollPane(table);
	scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
	scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
	JPanel addressPanel = new JPanel(new FlowLayout());
	addressPanel.setBackground(Color.BLUE);
	addressPanel.setForeground(Color.WHITE);
	addressPanel.setOpaque(true);
	JLabel addressHeader = new JLabel("Anschriften:");
	JPanel addressHeaderPanel = new JPanel();
	addressHeaderPanel.setBackground(Color.BLUE);
	addressHeaderPanel.setForeground(Color.WHITE);
	addressHeader.setOpaque(true);
	addressHeaderPanel.add(addressHeader);
	
	JButton buttonNew = new JButton("Neu");
	JButton buttonChange = new JButton("Ändern");
	JButton buttonDelete = new JButton ("Löschen");
	JPanel buttonsPanel = new JPanel(new FlowLayout());
	buttonsPanel.add(buttonNew);
	buttonsPanel.add(buttonChange);
	buttonsPanel.add(buttonDelete);
	addressPanel.add(buttonsPanel, FlowLayout.RIGHT);
	addressPanel.add(scroller, FlowLayout.CENTER);
	addressPanel.add(addressHeaderPanel, FlowLayout.LEFT);
	
	
	}	
	
	public final void showUI() {
		createUI();
		getMainFrame().setDialogPanel(this);
		getMainFrame().pack();
		this.setVisible(true);
	}
	
	@Override
	public void formToModel() {
	}

	@Override
	
	public void modelToForm() {
	}
	
	@Override
	
	public boolean validateUI() {
		return true;
	}
}



Code:
package com.client.gui;


import java.awt.BorderLayout;
import java.awt.Color;


import javax.swing.JPanel;
import javax.swing.JTable;



import com.client.application.MainFrame;
import com.client.gui.base.BasicDialogUI;
import com.client.page.base.BasicDialogPage;
import com.client.table.model.PartnerModel;


public class PartnerUI extends BasicDialogUI{

private static final long serialVersionUID =1024614598666310834L;
   
	public PartnerUI(MainFrame frame, BasicDialogPage page) {
		super(frame, page);
	}
    
	@Override
	public void createUI() {
		
		JPanel partnerPanel = new JPanel();
		partnerPanel.setBackground(Color.BLUE);
		partnerPanel.setForeground(Color.WHITE);
		partnerPanel.setOpaque(true);
		PartnerModel pm = new PartnerModel();
		JTable partnerTable = new JTable(pm);
		partnerTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		partnerTable.setColumnSelectionAllowed(true);
		partnerPanel.add(partnerTable, BorderLayout.CENTER);

	 	}

	@Override
	public final void showUI() {
		createUI();
		getMainFrame().setDialogPanel(this);
		getMainFrame().pack();
		this.setVisible(true);
	}
	
	@Override
	public void formToModel() {
	}

	@Override
	public void modelToForm() {
	}
	
	@Override
	public boolean validateUI() {
		return true;
	}

}
 

dayaftereh

Top Contributor
Hey also ich habe das so gelöst, ich habe in AddressUI das addressPanel also private Variabele gemacht und einen Getter für diese Variabele erzuegt. In der Klasse PartnerUI habe ich dan eine Instance von AddressUI erzugt und über den Getter mir das AddressPanel geholt. Hier mein Code:

AddressUI.java
Java:
package client.gui;

import java.awt.*;
import javax.swing.*;

import com.client.application.MainFrame;
import com.client.gui.base.BasicDialogUI;
import com.client.page.base.BasicDialogPage;
import com.client.table.model.AddressModel;

public class AddressUI extends BasicDialogUI {	
	
	private static final long serialVersionUID = -1214150134433745466L;
	
	private JPanel addressPanel = null;

	public AddressUI(MainFrame frame, BasicDialogPage page) {
		super(frame, page);
	}

	@Override
	public void createUI() {

		AddressModel am = new AddressModel();
		
		JTable table = new JTable(am);
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		table.setColumnSelectionAllowed(true);
		
		JScrollPane scroller = new JScrollPane(table);
		scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		
		addressPanel = new JPanel(new FlowLayout());		
		addressPanel.setBackground(Color.BLUE);
		addressPanel.setForeground(Color.WHITE);
		addressPanel.setOpaque(true);
		
		JLabel addressHeader = new JLabel("Anschriften:");
		addressHeader.setOpaque(true);
		
		JPanel addressHeaderPanel = new JPanel();		
		addressHeaderPanel.setBackground(Color.BLUE);
		addressHeaderPanel.setForeground(Color.WHITE);		
		addressHeaderPanel.add(addressHeader);

		JButton buttonNew = new JButton("Neu");
		JButton buttonChange = new JButton("Ändern");
		JButton buttonDelete = new JButton("Löschen");
		
		JPanel buttonsPanel = new JPanel(new FlowLayout());
		
		buttonsPanel.add(buttonNew);
		buttonsPanel.add(buttonChange);
		buttonsPanel.add(buttonDelete);
		
		addressPanel.add(buttonsPanel, FlowLayout.RIGHT);
		addressPanel.add(scroller, FlowLayout.CENTER);
		addressPanel.add(addressHeaderPanel, FlowLayout.LEFT);
	}

	public final void showUI() {
		createUI();
		getMainFrame().setDialogPanel(this);
		getMainFrame().pack();
		this.setVisible(true);
	}

	@Override
	public void formToModel() {
	}

	@Override
	public void modelToForm() {
	}

	@Override
	public boolean validateUI() {
		return true;
	}

	public JPanel getAddressPanel() {
		return addressPanel;
	}	
}

PartnerUI.java
Java:
import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JPanel;
import javax.swing.JTable;

import client.gui.AddressUI;

import com.client.application.MainFrame;
import com.client.gui.base.BasicDialogUI;
import com.client.page.base.BasicDialogPage;
import com.client.table.model.PartnerModel;

public class PartnerUI extends BasicDialogUI {

	private static final long serialVersionUID = 1024614598666310834L;
	
	private MainFrame frame = null;
	private BasicDialogPage page = null;

	public PartnerUI(MainFrame frame, BasicDialogPage page) {
		super(frame, page);
		this.frame = frame;
		this.page = page;		
	}

	@Override
	public void createUI() {

		JPanel partnerPanel = new JPanel();
		partnerPanel.setBackground(Color.BLUE);
		partnerPanel.setForeground(Color.WHITE);
		partnerPanel.setOpaque(true);
		
		PartnerModel pm = new PartnerModel();
		
		JTable partnerTable = new JTable(pm);
		partnerTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		partnerTable.setColumnSelectionAllowed(true);
		
		partnerPanel.add(partnerTable, BorderLayout.CENTER);
		
		AddressUI addressUI = new AddressUI(frame, page);
		// Hier dein addressPanel!!
		JPanel addressPanel = addressUI.getAddressPanel();

	}

	@Override
	public final void showUI() {
		createUI();
		getMainFrame().setDialogPanel(this);
		getMainFrame().pack();
		this.setVisible(true);
	}

	@Override
	public void formToModel() {
	}

	@Override
	public void modelToForm() {
	}

	@Override
	public boolean validateUI() {
		return true;
	}

}
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen


Oben