I used this code previously in netbeans 6.9.1 but it does not seem to work in 7.1.1, it underlines .getApplication() with the hint "cannot find symbol".
How can I make this work again?
JFrame mainFrame = TestProject.getApplication().getMainFrame();
AboutBox newAboutBox = new AboutBox();
newAboutBox.setLocationRelativeTo(mainFrame);
TestProject.getApplication().show(newAboutBox);
Here is a similar question, but the solution does not work.
Have you checked the static method getApplication() in TestProject.java? What does it show?
I found the solution by re-installing netbeans 6.9.1. It appears that there is a built-in library that is not in 7.1.1. I also found that the template I used was the "Desktop Application" template.
This is the solution I came up with from that:
TestProject class:
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
public class TestProject extends SingleFrameApplication {
#Override protected void startup() {
show(new AppView(this));
}
#Override protected void configureWindow(java.awt.Window root) { }
public static TestProject getApplication() {
return Application.getInstance(TestProject.class);
}
public static void main(String[] args) {
launch(TestProject.class, args);
}
}
AppView JFrame:
import org.jdesktop.application.FrameView;
import org.jdesktop.application.SingleFrameApplication;
public class AppView extends FrameView {
public AppView(SingleFrameApplication app) {
super(app);
JFrame mainFrame = TestProject.getApplication().getMainFrame();
AboutBox newAboutBox = new AboutBox();
newAboutBox.setLocationRelativeTo(mainFrame);
TestProject.getApplication().show(newAboutBox);
}
}
Related
I use gradle for build, Java, minecraft, Paper plugin
ctrl+f , figure out " the problem "
I made each of these plugins separately. Now, I am putting them together into one plugin but separating each class. Then, this error occurred. I want to solve this problem.
I thought third_function.third_listener could be used for that place, but It seems to be worng...
package com;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class mainclass extends JavaPlugin implements Listener {
#Override
public void onEnable() {
getLogger().warning("Server started.");
first_function first = new first_function(this);
first.onEnable();
second_function second = new second_function(this);
second.onEnable();
third_function third = new third_function(this);
third.onEnable();
PlayerJoinEvent third_listener;
third.onPlayerJoin(third_function.third_listener); // the problem. please help me, how can I get rid of this error?
}
}
class first_function implements Listener {
private final mainclass plugin;
first_function(mainclass plugin) {
this.plugin = plugin;
}
void onEnable() {
this.plugin.getLogger().warning("Hello, world!");
}
}
class second_function implements Listener {
private final mainclass plugin;
second_function(mainclass plugin) {
this.plugin = plugin;
}
void onEnable() {
World world = this.plugin.getServer().getWorld("world");
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
}
}
class third_function implements Listener {
private final mainclass plugin;
third_function(mainclass plugin) {
this.plugin = plugin;
}
Listener third_listener = (this);
void onEnable() {
this.plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
#EventHandler
void onPlayerJoin(PlayerJoinEvent event) {
event.getPlayer().sendActionBar(Component.text("Welcome",(NamedTextColor.BLUE)));
}
}
You should register the listener and not try to call the method yourself. For example:
#Override
public void onEnable() {
third_function third = new third_function(this);
getServer().getPluginManager().registerEvents(third, this);
}
Also, I mostly suggest you to use global java names convention, such as name ThirdFunction instead of third_function for example
I created this ArrayLocation.java yesterday
public class ArrayLocation {
private double coords[];
public ArrayLocation (double[] coords) {
this.coords = coords;
}
public static void main (String[] args) {
double[] coords = {5.0, 0.0};
ArrayLocation accra = new ArrayLocation (coords);
coords[0] = 32.9;
coords[1] = -117.2;
System.out.println(accra.coords[0]);
}
} ---This ran well and gave me an output 32.9
Today I created a new project and added this MyDisplay.java to it
package guimodule;
import processing.core.PApplet;
public class MyDisplay extends PApplet {
public void setup(){
size(400, 600);
}
public void draw(){
}
}
But when I run MyDisplay.java eclipse is still running the old ArrayLocation.java and returning 32.9. I expected it would open a blank applet.
Please help. I am pretty new to eclipse
How should I tell eclipse to run MyDisplay.java and not ArrayLocation.java ?
Goto Projects -> Clean
Open your java file in the editor, right click Run as -> Java Application
There is no main method in your MyDisplay.java.
Check your BuildAnt
it will surely help you.
Cheers.
You may add main method to MyDisplay.java class itself as follows:
package guimodule;
import processing.core.PApplet;
public class MyDisplay extends PApplet {
public void setup(){
size(400, 600);
}
public void draw(){
}
public static void main(String args[]){
PApplet.main(new String[] {"guimodule.MyDisplay"});
}
}
OR you can also initiate your MyDisplay.java from other class having main function:
InitClass.java
public class InitClass{
public static void main(String args[]){
final MyDisplay disp = new MyDisplay();
disp.init();
}
I'm trying to implement TextFX in my project to do some UI testing. However it seems I can't get it to work properly. I've downloaded the jars from http://search.maven.org/#search%7Cga%7C1%7Ctestfx to a folder named 'TestFX-3.1.2' on my system.
Afterwards I've created a new library in Netbeans8 pointing to those jar files (jar, source and javadoc). As a matter of test I've created a simple Java FXML project with the new library added.
public class Test2 extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Next to that I have a controller for my FXML file with the following generated code:
public class FXMLDocumentController implements Initializable {
#FXML
private Label label;
#FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
To implement the TestFX side, I've created a new class that extends GuiTest:
package test2;
import java.io.IOException;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import org.loadui.testfx.GuiTest;
public class TestTheThing extends GuiTest {
#Override
protected Parent getRootNode() {
FXMLLoader loader = new FXMLLoader();
Parent node = null;
try {
node = loader.load(this.getClass().getResource("FXMLDocument.fxml").openStream());
} catch (IOException e) {
System.out.println(e.toString());
}
return node;
}
#Test //<-- this Annotiation does not work
public void pressTheButton(){
//TODO
}
}
As said above in the code, the #Test simply does not work and is red underlined with the warning 'cannot find symbol'. Could anyone point me in the right direction about what I'm doing wrong?
According to https://repo1.maven.org/maven2/org/loadui/testFx/3.1.2/testFx-3.1.2.pom, testFx has several dependencies (guava, junit, hamcrest-all, hamcrest-core). To work correctly, you need to add the jars corresponding to these dependencies to your project. However, using maven is the recommended approach for that.
Don't load your fxml file directly in the test class as it may not work intentionally. Instead launch main class this way:
FXTestUtils.launchApp(Test2.class);
Thread.sleep(2000);
controller = new GuiTest()
{
#Override
protected Parent getRootNode()
{
return Test2.getStage().getScene().getRoot();
}
};
Create a static method getStage() in your Test2 class that returns the Stage. The above code should reside in a method annoted with #BeforeClass in your test class. The controller is a static reference to the GuiTest.
In the end your test class should look something like this:
import java.io.IOException;
import javafx.scene.Parent;
import org.loadui.testfx.GuiTest;
import org.loadui.testfx.utils.FXTestUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestTheThing
{
public static GuiTest controller;
#BeforeClass
public static void setUpClass() throws InterruptedException, IOException
{
FXTestUtils.launchApp(Test2.class);
Thread.sleep(2000);
controller = new GuiTest()
{
#Override
protected Parent getRootNode()
{
return Test2.getStage().getScene().getRoot();
}
};
}
#Test
public void testCase()
{
System.out.println("in a test method");
}
}
In this case you will not need to extend from GuiTest. And, don't forget to create static getStage() in Test2 class. Hope this will help. This is working fine in my case.
I followed these instructions using the Eclipse IDE:
http://blogs.locusta.gr/argy/2011/09/setup-an-apache-pivot-project-in-eclipse/
So now I've imported and attached the respective Apache Pivot libraries. I tried to run this code they have on their website, but a proper main method is missing. Eclipse has underlined the first line of the code as an error.
This is the error I get:
Error: Main method not found in class HelloJava, please define the main method
as: public static void main(String[] args)
I understand the error, but what should the main method contain? https://www.mail-archive.com/user#pivot.apache.org/msg06027.html
This guy suggests the following
public static void main(String[] args) {
DesktopApplicationContext.main(HelloJava.class, args);
}
But this returns the error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
DesktopApplicationContext cannot be resolved
Anyone got any ideas? Here is the code, I'm pretty sure only the first bits are important:
package org.apache.pivot.tutorials;
import java.awt.Color;
import java.awt.Font;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.HorizontalAlignment;
import org.apache.pivot.wtk.Label;
import org.apache.pivot.wtk.VerticalAlignment;
import org.apache.pivot.wtk.Window;
public class HelloJava implements Application {
private Window window = null;
public static void main(String[] args) {
DesktopApplicationContext.main(HelloJava.class, args);
}
#Override
public void startup(Display display, Map<String, String> properties) {
window = new Window();
Label label = new Label();
label.setText("Hello World!");
label.getStyles().put("font", new Font("Arial", Font.BOLD, 24));
label.getStyles().put("color", Color.RED);
label.getStyles().put("horizontalAlignment",
HorizontalAlignment.CENTER);
label.getStyles().put("verticalAlignment",
VerticalAlignment.CENTER);
window.setContent(label);
window.setTitle("Hello World!");
window.setMaximized(true);
window.open(display);
}
#Override
public boolean shutdown(boolean optional) {
if (window != null) {
window.close();
}
return false;
}
#Override
public void suspend() {
}
#Override
public void resume() {
}
}
Never mind, I fixed it. I just had to erase the first line of the code, and add:
import org.apache.pivot.wtk.DesktopApplicationContext;
my code, being practically identical to the code given in BlackBerry's tutorial, has a syntax error in Eclipse. i'm sure there is some small but i'm just not seeing, but my coworker could not find it as well. any ideas would be greatly appreciated. thanks!
Code:
pushScreen(new ABCScreen());
Error:
Cannot make a static reference to the
non-static method pushScreen(Screen)
from the type UiApplication
here is the complete source:
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class AwesomeBBCalculator extends UiApplication {
public AwesomeBBCalculator() {
AwesomeBBCalculator app = new AwesomeBBCalculator();
app.enterEventDispatcher();
}
public static void main(String[] args) {
pushScreen(new ABCScreen()); // ERROR LINE
}
}
final class ABCScreen extends MainScreen {
public ABCScreen() {
super();
// add title
LabelField title = new LabelField("Awesome BlackBerry Calculator",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
}
public boolean onClose() {
Dialog.alert("Thanks for using the Awesome BlackBerry Calculator!\nGoodbye.");
System.exit(0);
return true;
}
}
The pushScreen method can only be called within an instance of UiApplication. You are trying to call it from a static main method. That does not work. Do this instead...
public void foo()
{
pushScreen(this);
}
public static void main(String[] args)
{
(new ABCScreen()).foo();
}
public void class1()
{
pushScreen(this);
}
public static void main(String[] args)
{
(new NewScreen()).class1();
}
try making an object for the ABCScreen class and then use it or u may try this also:
UiApplication.getUiApplication().pushScreen(new ABCScreen());