When is updateItem() method in TableCell called?
Is it when Property associated with that cell changes?
In my application I have a thread that downloads content based on hyperlink provided.I have a TableView that displays name and progress of download in two different columns.In the progress column I wanted to have a progressbar and a label at the center of progressbar which displays % downloaded.For that I took help from Progressbar and label in tablecell.But it seems that updateItem() method is not reading the 'progress' variable and -1 is getting read everytime.
Progress.setCellValueFactory(new PropertyValueFactory<Download, Double>("progress"));
Progress.setCellFactory(new Callback<TableColumn<Download, Double>, TableCell<Download, Double>>() {
#Override
public TableCell<Download, Double> call(TableColumn<Download, Double> param) {
return new TableCell<Download, Double>(){
ProgressBar bar=new ProgressBar();
public void updateItem(Double progress,boolean empty){
if(empty){
System.out.println("Empty");
setText(null);
setGraphic(null);
}
else{
System.out.println(progress);
bar.setProgress(progress);
setText(progress.toString());
setGraphic(bar);
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
}
}
};
}
});
ADT of my Download Class
public class Download extends Task<Void>{
private String url;
public Double progress;
private int filesize;
private STATE state;
private Observer observer;
public Object monitor;
private String ThreadName;
private int id;
public static enum STATE{
DOWNLOADING,PAUSE,STOP;
}
public Download(String url,Observer observer,Object monitor){
this.url=url;
this.observer=observer;
this.monitor=monitor;
progress=new Double(0.0d);
}
In the run method of Download class I am continuously updating 'progress' variable by adding to it the number of downloaded bytes.
There is a progress property in Task, but it is not modified if you write to the progress field you added. (PropertyValueFactory uses methods to retrieve the result, not fields and a Double field does not provide a way to observe it anyways.)
updateProgress should be used to update this property to ensure the property is properly synchronized with the application thread.
e.g.
public class Download extends Task<Void>{
protected Void call() {
while (!(isCancelled() || downloadComplete())) {
...
// update the progress
updateProgress(currentWorkDone / totalWork);
}
return null;
}
}
Related
My use-case:
a custom property on a control that should be configurable via css
the property must be changeable at runtime
for a given instance of the control, the programmatic change must not be reverted on re-applying the css
A custom StyleableProperty looks like a perfect match to implement the requirement. Below is an example that implements (taken without change from the class javadoc of StyleablePropertyFactory).
All is fine except for the last requirement: on applyCss, the default value from the stylesheet is reapplied. To reproduce:
run the example, note that the initial "selected" state (the checkbox' selected is bound it) of the MyButton is true
click the custom button, note that the "selected" doesn't change to false (though the actionHandler changes it)
click on the second ("toggle") button, note that the selected state of the custom button changes to false
hover the mouse over the custom button, note that the selected state falls back to true
The reason for falling back to true (the value set via style), can be traced to applyCss which happens on state changes ... which is understandable and might be the correct thingy-to-do most of the times, but not in my context.
So the questions:
am I on the right track with using StyleableProperty?
if so, how to tweak such that it's not re-apply after a manual change has happened?
if not, what else to do?
or maybe asking the wrong questions altogether: maybe properties which are settable via css are not meant to be (permanently) changed by code?
The example:
public class StyleableButtonDriver extends Application {
/**
* example code from class doc of StyleablePropertyFactory.
*/
private static class MyButton extends Button {
private static final StyleablePropertyFactory<MyButton> FACTORY
= new StyleablePropertyFactory<>(Button.getClassCssMetaData());
MyButton(String labelText) {
super(labelText);
getStyleClass().add("my-button");
setStyle("-my-selected: true");
}
// Typical JavaFX property implementation
public ObservableValue<Boolean> selectedProperty() { return (ObservableValue<Boolean>)selected; }
public final boolean isSelected() { return selected.getValue(); }
public final void setSelected(boolean isSelected) { selected.setValue(isSelected); }
// StyleableProperty implementation reduced to one line
private final StyleableProperty<Boolean> selected =
FACTORY.createStyleableBooleanProperty(
this, "selected", "-my-selected", s -> s.selected);
#Override
public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData() {
return FACTORY.getCssMetaData();
}
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
return FACTORY.getCssMetaData();
}
}
private Parent createContent() {
MyButton button = new MyButton("styleable button");
button.setOnAction(e -> {
// does not work: reset on applyCss
boolean isSelected = button.isSelected();
button.setSelected(!isSelected);
});
CheckBox box = new CheckBox("button selected");
box.selectedProperty().bind(button.selectedProperty());
Button toggle = new Button("toggle button");
toggle.setOnAction(e -> {
boolean isSelected = button.isSelected();
button.setSelected(!isSelected);
});
BorderPane content = new BorderPane(button);
content.setBottom(new HBox(10, box, toggle));
return content;
}
#Override
public void start(Stage stage) throws Exception {
stage.setScene(new Scene(createContent(), 300, 200));
//same behavior as setting the style directly
// URL uri = getClass().getResource("xstyleable.css");
// stage.getScene().getStylesheets().add(uri.toExternalForm());
// not useful: would have to override all
// Application.setUserAgentStylesheet(uri.toExternalForm());
stage.setTitle(FXUtils.version());
stage.show();
}
public static void main(String[] args) {
launch(args);
}
#SuppressWarnings("unused")
private static final Logger LOG = Logger
.getLogger(StyleableButtonDriver.class.getName());
}
You are on the right track, but since you need to override the default priority of the style origins (user agent stylesheet < programmatically assigned < css stylesheet < Node.style property), you cannot use SyleablePropertyFactory for creating this property. You need to create a CssMetaData object that indicates a property as non-setable, if the property was programatically assigned.
private static class MyButton extends Button {
private static final List<CssMetaData<? extends Styleable, ?>> CLASS_CSS_METADATA;
private static final CssMetaData<MyButton, Boolean> SELECTED;
static {
SELECTED = new CssMetaData<MyButton, Boolean>("-my-selected", StyleConverter.getBooleanConverter()) {
#Override
public boolean isSettable(MyButton styleable) {
// not setable, if bound or set by user
return styleable.selected.getStyleOrigin() != StyleOrigin.USER && !styleable.selected.isBound();
}
#Override
public StyleableProperty<Boolean> getStyleableProperty(MyButton styleable) {
return styleable.selected;
}
};
// copy list of button css metadata to list and add new metadata object
List<CssMetaData<? extends Styleable, ?>> buttonData = Button.getClassCssMetaData();
List<CssMetaData<? extends Styleable, ?>> mybuttonData = new ArrayList<>(buttonData.size()+1);
mybuttonData.addAll(buttonData);
mybuttonData.add(SELECTED);
CLASS_CSS_METADATA = Collections.unmodifiableList(mybuttonData);
}
MyButton(String labelText) {
super(labelText);
getStyleClass().add("my-button");
setStyle("-my-selected: true");
}
// Typical JavaFX property implementation
public ObservableValue<Boolean> selectedProperty() { return selected; }
public final boolean isSelected() { return selected.get(); }
public final void setSelected(boolean isSelected) { selected.set(isSelected); }
// StyleableProperty implementation reduced to one line
private final SimpleStyleableBooleanProperty selected = new SimpleStyleableBooleanProperty(SELECTED, this, "selected");
#Override
public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData() {
return CLASS_CSS_METADATA;
}
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
return CLASS_CSS_METADATA;
}
}
I want to do the following and I would need some suggestions on what is the best way to do it.
I have a JList which displays the files that the user adds by clicking add (+) button and removes the files when the user clicks remove (-) button. With each added file, I want to associate an icon which should indicate the status of the file. For example, if the user has only added the file and not run the file (I have another JButton for running the application with the selected file), then this icon should be red and once the user runs it, this icon should change to green. Also, if the user removes the file by clicking the (-) button, it should remove the icon associated with that particular file too. Below is a pictorial representation of what I want.
I was thinking of associating a ImageIcon with each added file but I am not sure how to change its appearance to display the status. I am also not sure how the ImageIcon can be removed when the file is removed. Is there any other way (other than ImageIcon) to do it? Any help/suggestions are appreciated.
In programming, data is king. How that data get's represented should not be of consideration to the data, that's the domain/responsibility of the UI/view layers.
This is often represented by the model-view-controller pattern
In your example, you have two pieces of (basic) information. A file and a status (not run, run, deleted), you want to combine this information as "data". In Java, that typically means a Plain Old Java Object (or Pojo)
Because the status only has a limited number of possibilities, we can use a enum to represent it, and thereby restricting the valid values
public enum FileStatus {
NOT_RUN, RUN, DELETED;
}
And then we can create our own pojo...
public class FileOperation {
private File file;
private FileStatus status;
public FileOperation(File file, FileStatus status) {
this.file = file;
this.status = status;
}
public FileOperation(File file) {
this(file, FileStatus.NOT_RUN);
}
public File getFile() {
return file;
}
public FileStatus getStatus() {
return status;
}
public void setStatus(FileStatus newStatus) {
if (status == newStatus) {
return;
}
this.status = newStatus;
}
}
Now, when we want to know the status of the file, we know where to get it.
But what about the JList? You ask, good question. What we really want is some way that the JList can be informed when the status of any FileOperation object changes.
Now, you could iterate over the ListModel, but that's not a very clean solution, a better solution is to allow the FileOperation to generate events when it changes and have the ListModel listen for them and take it's own action.
This is a basic concept of an observer patternÆ’
There's a number of ways you might do this, but I'm lazy, so I'm just going to use the available property change API
public class FileOperation {
private File file;
private FileStatus status;
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public FileOperation(File file, FileStatus status) {
this.file = file;
this.status = status;
}
public FileOperation(File file) {
this(file, FileStatus.NOT_RUN);
}
public File getFile() {
return file;
}
public FileStatus getStatus() {
return status;
}
public void setStatus(FileStatus newStatus) {
if (status == newStatus) {
return;
}
FileStatus oldStatus = status;
status = newStatus;
propertyChangeSupport.firePropertyChange("status", oldStatus, status);
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}
}
And now we need a ListModel which can respond to it...
public class FileOperationListModel extends AbstractListModel<FileOperation> {
private List<FileOperation> items = new ArrayList<FileOperation>(25);
private PropertyChangeListener handler = new PropertyChangeHandler();
public void add(FileOperation fo) {
fo.addPropertyChangeListener(handler);
int size = items.size();
items.add(fo);
fireIntervalAdded(this, size, size);
}
public void remove(FileOperation fo) {
int index = items.indexOf(fo);
if (index < 0) {
return;
}
fo.removePropertyChangeListener(handler);
items.remove(fo);
fireIntervalRemoved(this, index, index);
}
#Override
public int getSize() {
return items.size();
}
#Override
public FileOperation getElementAt(int index) {
return items.get(index);
}
public class PropertyChangeHandler implements PropertyChangeListener {
#Override
public void propertyChange(PropertyChangeEvent evt) {
if (!(evt.getSource() instanceof FileOperation)) {
return;
}
FileOperation fo = (FileOperation) evt.getSource();
int index = items.indexOf(fo);
fireContentsChanged(FileOperationListModel.this, index, index);
}
}
}
Now, the final piece of the puzzle, is you're going to need a custom ListCellRenderer which can display the information you want.
For that, you're going to have to start by reading How to use lists and Writing a Custom Cell Renderer
I have a simple example of the add-on switch with vaadin, what I want is to keep the state of the switch even when I update the UI, that is, I support multiple tabs, but I can not do it, this push example is very similar to What I want to do but with a textField.
https://github.com/vaadin-marcus/push-example/blob/master/src/main/java/com/vaadin/training/ScrumBoardLayout.java
https://github.com/rucko24/MVP/blob/testingSwitchPushTemu/src/main/java/com/Core/vaadin/pushServer/ejemploPushMarkus/ScrumBoard.java
To my example I add a bulb so that when another accesses the application can see the current state of the bulb. My example in github is this with only 3 classes
https://github.com/rucko24/MVP/tree/testingSwitchPushTemu/src/main/java/com/Core/vaadin/pushServer/ejemploPushMarkus
This is the swithc listener that changes my bulb, but when I get the boolean value (true, or false), I still do not understand the right way to push the other switch
switchTemu.addValueChangeListener(new Property.ValueChangeListener() {
private static final long serialVersionUID = 1L;
#Override
public void valueChange(Property.ValueChangeEvent event) {
boolean estado = (boolean) event.getProperty().getValue();
ScrumBoard.addSwitch(estado);
switchTemu.removeValueChangeListener(this);
if(estado == Boolean.TRUE) {
bombilla.setIcon(bombillaON);
}else {
bombilla.setIcon(bombillaOFF);
}
switchTemu.addValueChangeListener(this);
}
});
Update
In my example github achievement, change the state of all switches to all UI, but I still do not know how to get the state of the switches
I made a couple of changes to your sources (still basic, but it gets you started):
only 1 common shared state
switch value change listeners now just trigger a state changed event
state changed listeners now update the UI elements when triggered
upon registration, a state changed listeners is informed (triggered) about the current state
The main idea is to have just a single shared state and any change is communicated to all the listeners (including the one where the change originated).
Below you can find the code: (P.S. I did not recompile my widgetset so the nice switch icon falls back to the default check box style)
1) SwitchState - represents the state of the switch shared between all the app instances
public enum SwitchState {
ON(true, new ThemeResource("img/on.png")), OFF(false, new ThemeResource("img/off.png"));
private final boolean value;
private final ThemeResource icon;
SwitchState(boolean value, ThemeResource icon) {
this.value = value;
this.icon = icon;
}
public boolean getValue() {
return value;
}
public ThemeResource getIcon() {
return icon;
}
public static SwitchState from(boolean value) {
return value ? ON : OFF;
}
}
2) ScrumBoard common state and listeners manager
public class ScrumBoard {
// list of listeners
private static List<SwitchChangeListener> LISTENERS = new ArrayList<>();
// initial state
private static SwitchState STATE = SwitchState.OFF;
// state change listener contract
public interface SwitchChangeListener {
void handleStateChange(SwitchState state);
}
// handle a a state change request
public static synchronized void updateState(boolean value) {
STATE = SwitchState.from(value);
fireChangeEvent(STATE);
}
// register a new state listener
public static synchronized void addSwitchChangeListener(SwitchChangeListener listener) {
System.out.println("Added listener for " + listener);
LISTENERS.add(listener);
// when a new listener is registered, also inform it of the current state
listener.handleStateChange(STATE);
}
// remove a state listener
public static synchronized void removeSwitchListener(SwitchChangeListener listener) {
LISTENERS.remove(listener);
}
// fire a change event to all registered listeners
private static void fireChangeEvent(SwitchState state) {
for (SwitchChangeListener listener : LISTENERS) {
listener.handleStateChange(state);
}
}
}
3) ScrumBoardLayout - UI layout and components
public class ScrumBoardLayout extends VerticalLayout implements ScrumBoard.SwitchChangeListener {
private Label icon = new Label();
private Switch mySwitch = new Switch();
public ScrumBoardLayout() {
setMargin(true);
setSpacing(true);
addHeader();
// listen for state changes
ScrumBoard.addSwitchChangeListener(this);
}
private void addHeader() {
mySwitch.setImmediate(true);
icon.setSizeUndefined();
// notify of state change
mySwitch.addValueChangeListener((Property.ValueChangeListener) event -> ScrumBoard.updateState((Boolean) event.getProperty().getValue()));
VerticalLayout layout = new VerticalLayout();
layout.setHeight("78%");
layout.addComponents(icon, mySwitch);
layout.setComponentAlignment(icon, Alignment.BOTTOM_CENTER);
layout.setComponentAlignment(mySwitch, Alignment.BOTTOM_CENTER);
layout.setExpandRatio(mySwitch, 1);
addComponents(layout);
}
#Override
public void handleStateChange(SwitchState state) {
// update UI on state change
UI.getCurrent().access(() -> {
mySwitch.setValue(state.getValue());
icon.setIcon(state.getIcon());
Notification.show(state.name(), Type.ASSISTIVE_NOTIFICATION);
});
}
#Override
public void detach() {
super.detach();
ScrumBoard.removeSwitchListener(this);
}
}
4) Result
I could see that with the ThemeResource () class, changing the bulb to its ON / OFF effect is strange, but I solve it as follows
.bombillo-on {
#include valo-animate-in-fade($duration: 1s);
width: 181px;
height: 216px;
background: url(img/on.png) no-repeat;
}
.bombillo-off {
#include valo-animate-in-fade($duration: 1s);
width: 181px;
height: 216px;
background: url(img/off.png) no-repeat;
}
public enum Sstate {
ON(true,"bombillo-on"),
OFF(false,"bombillo-off");
private boolean value;
private String style;
Sstate(boolean value, String style) {
this.value = value;
this.style = style;
}
public boolean getValue() { return value;}
public String getStyle() { return style;}
public static Sstate from(boolean value) { return value ? ON:OFF;}
}
And the handleChangeEvent It stays like this
#Override
public void handleChangeEvent(Sstate state) {
ui.access(() -> {
bombilla.setStyleName(state.getStyle());
s.setValue(state.getValue());
System.out.println(state+" values "+s);
});
}
UPDATE:
I notice an issue, that when I add a new view, or change using the buttonMenuToggle, it loses the synchronization, and update the bulb quite strange, clear with the themeResource does not happen that.
Solution:
to avoid UiDetachedException when using the Navigator try this, It works very well
#Override
public void handleChangeEvent(Sstate state) {
if(!ui.isAttached()) {
BroadcastesSwitch.removeListener(this);
return;
}
ui.access(() -> {
bombilla.setStyleName(state.getStyle());
s.setValue(state.getValue());
System.out.println(state+" values "+s);
});
}
My problem is that I have just created a cellTable but it doesn't work because I see this on my broswer
The red border is of the FlowPanel that contains the table that has a black border, on side there is the GWT.log
Now I've tried everything but I don't know why, maybe it doesn't load the table for something reason. However I'm sure that dataProvider works beacause, as tou can see, the log show that data 'Carrello' are load on the column of my table 'carrello'. Here the code of table:
public class ShopTable extends CellTable {
private CellTable<Carrello> carrello;
private Column<Carrello, String> columnTitolo;
private Column<Carrello, String> columnTipoSupporto;
private AsyncDataProviderCarrello dataProvider;
private String COLUMN_NAME_TITOLO="Titolo film";
private String COLUMN_NAME_SUPPORTO="Tipo";
public ShopTable(){
carrello=new CellTable<>();
createTable();
createWithAsyncDataProvider();
GWT.log("Column example: "+carrello.getColumn(0).toString());
}
private void createTable(){
columnTitolo=buildColumnTitolo();
columnTipoSupporto=buildColumnTipoSupporto();
// NEED TO ADD HEADER (and FOOTER MAYBE)
carrello.addColumn(columnTitolo, "Titolo Film");
carrello.addColumn(columnTipoSupporto, "Tipo");
}
private Column<Carrello, String> buildColumnTitolo(){
columnTitolo=new Column<Carrello, String>(new EditTextCell()) {
#Override
public String getValue(Carrello object) {
GWT.log("aggiungo a carrelloTable: "+object);
return object.getTitolo();
}
};
columnTitolo.setDataStoreName(COLUMN_NAME_TITOLO);
return columnTitolo;
}
private Column<Carrello, String> buildColumnTipoSupporto(){
columnTipoSupporto=new Column<Carrello, String>(new EditTextCell()) {
#Override
public String getValue(Carrello object) {
GWT.log("aggiungo a carrelloTable: "+object);
return object.getTipoSupporto().toString();
}
};
columnTipoSupporto.setDataStoreName(COLUMN_NAME_TITOLO);
return columnTipoSupporto;
}
private void createWithAsyncDataProvider(){
dataProvider=new AsyncDataProviderCarrello();
dataProvider.addDataDisplay(carrello);
dataProvider.updateRowCount(10, false);
//.. SORTING METHOD NEED TO ADD
}
}
Here the code of Widget UIBinder that use the ShopTable
public class CarrelloPage extends Composite {
private static CarrelloPageUiBinder uiBinder = GWT.create(CarrelloPageUiBinder.class);
interface CarrelloPageUiBinder extends UiBinder<Widget, CarrelloPage> {
}
interface MyStyle extends CssResource{
String carrelloTable();
}
#UiField MyStyle style;
#UiField FlowPanel spazio_carrello;
/**
* necessario per dimensionare ad hoc per
* il pannello
*/
private ShopTable carrello;
private void resizeWidget(){
setWidth("100%");
setHeight(Window.getClientHeight() + "px");
}
public CarrelloPage() {
carrello=new ShopTable();
initWidget(uiBinder.createAndBindUi(this));
carrello.setStyleName(style.carrelloTable());
spazio_carrello.add(carrello);
resizeWidget();
Window.addResizeHandler(resizeHandler);
}
private ResizeHandler resizeHandler = new ResizeHandler()
{
public void onResize (ResizeEvent event)
{
setWidgetToMaxWidthAndHeight();
}
};
private void setWidgetToMaxWidthAndHeight ()
{
setWidth("100%");
setHeight(Window.getClientHeight() + "px");
}
}
Thanks for attention!
Your CellTable has a height of zero. This is why you don't see it.
You either have to set height of your CellTable in code, or you should add it to a widget that implements ProvidesResize interface, like a LayoutPanel.
STARTED - 3:00PM
UPDATE 1 - 5:36PM
Apply Button in the Option() class:
private void cmdApplyActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
hud.setTime(btnTxtTime);
hud.setTemp(btnTxtTemp);
hud.setSurface(btnTxtSurface);
hud.setWeather(btnTxtWeather);
hud.setRadiation(btnTxtRadiation);
dispose();
}
This is a section of the Option() Class.
public class Options extends javax.swing.JFrame {
public String btnTxtTime;
public String btnTxtTemp;
public String btnTxtSurface;
public String btnTxtWeather;
public String btnTxtRadiation;
public static boolean ApplyClicked;
/**
* Creates new form Profile
*/
private HUD hud;
public Options(HUD hud) {
initComponents();
this.hud = hud;
}
This is a method in Option() class:
public String getTime() {
if ("Day".equals(grpTimeOfDay.getSelection())) {
btnTxtTime = "Day";
return this.btnTxtTime;
}
if ("Night".equals(grpTimeOfDay.getSelection())) {
btnTxtTime = "Night";
return this.btnTxtTime;
}
return null;
}
This is how Options() is openned from within HUD():
private void cmdOptionsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Options o = new Options(hud);
this.getLocation(p);
o.setLocation((int) p.getX() + 100, (int) p.getY() + 100);
o.setVisible(true);
}
This is the start of my HUD() Class:
public abstract class HUD extends javax.swing.JFrame implements Runnable {
private Options o;
private HUD hud;
public HUD(Options o) {
initComponents();
this.o = o;
and this is the method from HUD() which gets the value of the JButtons from Options():
public void setTime(String strTime) {
strTime = o.getTime();
txtTime.setText(strTime);
}
However whenever I click Apply, the options set in Options() are not then set in the TextFields that display them in HUD() like they should be :/
It's difficult to navigate through your very lengthy code sample, however take a look at your cmdApplyActionPerformed() method. You are creating a new HUD() and setting values in it... and then doing absolutely nothing with it.
If you are trying to use the "Apply" button to modify an existing HUD object, your class needs to have a reference to it somewhere. If the HUD is the parent class which creates the Options, try having the Options store a reference to the parent in its constructor. Then, when you perform changes like this in the Options, you can perform them on the parent rather than on a new variable which has no effect.
private HUD parent;
/**
* Creates new form Profile
*/
public Options(HUD parent) {
initComponents();
this.parent = parent;
}
Then, in your event handler, you can have ...
parent.setTime(btnTxtTime);
parent.setTemp(btnTxtTemp);
parent.setSurface(btnTxtSurface);
parent.setWeather(btnTxtWeather);
parent.setRadiation(btnTxtRadiation);
dispose();
From what I understand, HUD is your 'main window' and the users gets to this option frame from that window.
But when you apply, you're setting the properties on a new HUD, not the one you had before.
To fix this, you need a handle to your main window in your config window, so that you can set the properties on it.
in your hud:
ConfigFrame config = new ConfigFrame();
config.setHUD(this);
config.setVisible(true);
In your config
private HUD hud;
public void setHUD(HUD hud){
this.hud = hud;
}
then just leave out the HUD hud = new hud();