Last active
March 23, 2020 11:24
-
-
Save teguhteja/4941004d485c37b7642dea6842a54cd1 to your computer and use it in GitHub Desktop.
Example GUI For Test Swing Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ttm.testswingmaven; | |
import static javax.swing.SwingUtilities.invokeAndWait; | |
import static org.assertj.swing.aut.util.swing.ButtonUtil.addActionToButton; | |
import static org.assertj.swing.aut.util.swing.ButtonUtil.newButton; | |
import static org.assertj.swing.aut.util.swing.LabelUtil.newLabel; | |
import static org.assertj.swing.aut.util.swing.TextFieldUtil.newTextField; | |
import java.lang.reflect.InvocationTargetException; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JTextField; | |
import net.miginfocom.layout.AC; | |
import net.miginfocom.layout.LC; | |
import org.assertj.swing.aut.components.SampleFrame; | |
public class SimpleCopyApplication extends SampleFrame { | |
private static final long serialVersionUID = 1L; | |
public SimpleCopyApplication() { | |
setMiglayout(new LC().wrapAfter(1), new AC().align("center"), new AC()); | |
final JTextField textField = newTextField("textToCopy"); | |
JButton button = newButton("copyButton", "Copy text to label"); | |
final JLabel label = newLabel("copiedText"); | |
addActionToButton(button, new Runnable() { | |
@Override | |
public void run() { | |
label.setText(textField.getText()); | |
} | |
}); | |
add(textField); | |
add(button); | |
add(label); | |
pack(); | |
} | |
public static void main(String[] args) throws InvocationTargetException, InterruptedException { | |
invokeAndWait(new Runnable() { | |
@Override | |
public void run() { | |
JFrame frame = new SimpleCopyApplication(); | |
frame.setVisible(true); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment