Hi,
First I want to say that I love the work you have done developing Ja.NET. This is a really useful tool to have in the tool box!
First issue is that I am getting a runtime exception when calling java code from a .NET 3.5 WPF application (code below).
A first chance exception of type 'java.lang.ExceptionInInitializerError' occurred in janet.awt.dll
java.lang.ExceptionInInitializerError: The type initializer for 'org.apache.harmony.awt.nativebridge.NativeBridge' threw an exception.
Second issue: Is there a way to add the Java gui component to a StackPanel? or (not prefered) a Windows Form?
Build steps:
1) create java app in Netbeans (JDK 1.6.0_16-b01)
2) C:\Ja.NET\bin\javac.exe -bam:javaapplication.dll .\JavaApplication\src\javaapplication\*.java
3) create C# project
4) add references to C:\Ja.NET\jre\bin\default\*.dll
5) add reference to javaapplication.dll
************************************ Java code ************************************
NewJPanel.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication;
/**
*
* @author rvanamb
*/
public class NewJPanel extends javax.swing.JPanel implements javax.swing.event.ChangeListener {
/** Creates new form NewJPanel */
public NewJPanel(){
this.setName("Form");
this.setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
this.jColorChooser1 = new javax.swing.JColorChooser();
this.jColorChooser1.setName("jColorChooser1");
//this.jColorChooser1.setLayout(this.getLayout());
this.jColorChooser1.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT);
this.jColorChooser1.setAlignmentY(java.awt.Component.TOP_ALIGNMENT);
this.add(this.jColorChooser1);
this.jPanel1 = new javax.swing.JPanel();
this.jPanel1.setName("jPanel1");
//this.jPanel1.setLayout(this.getLayout());
this.jPanel1.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT);
this.jPanel1.setAlignmentY(java.awt.Component.BOTTOM_ALIGNMENT);
this.add(this.jPanel1);
this.jColorChooser1.getSelectionModel().addChangeListener(this);
this.validate();
}
public void stateChanged(javax.swing.event.ChangeEvent e) {
this.jPanel1.setBackground(this.jColorChooser1.getColor());
}
// Variables declaration - do not modify
private javax.swing.JColorChooser jColorChooser1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication;
/**
*
* @author rvanamb
*/
public class Main {
public static javax.swing.JFrame show()
{
javax.swing.JFrame frame = new javax.swing.JFrame();
frame.setSize(500, 550);
NewJPanel newJPanel = new NewJPanel();
frame.add(newJPanel);
frame.validate();
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
return frame;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
show();
}
}
************************************ C# code ************************************
Window1.xaml
<Window x:Class="EmbededJava.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Embedded Java" Height="353" Width="343">
<StackPanel Name="stackPanel1" Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="300" MinWidth="300" Height="312" Width="320">
<StackPanel Name="stackPanel2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Orientation="Horizontal" >
<Label>Java App 1</Label>
<Button Height="23" Name="button_init_1" Width="75" Click="button_init_1_Click">Init</Button>
</StackPanel>
<StackPanel Name="stackPanel3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Orientation="Horizontal" >
<Label>Java App 2</Label>
<Button Height="23" Name="button_init_2" Width="75" Click="button_init_2_Click">Init</Button>
</StackPanel>
</StackPanel>
</Window>
Window1.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace EmbededJava
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void button_init_1_Click(object sender, RoutedEventArgs e)
{
try
{
javax.swing.JFrame frame = javaapplication.Main.show();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
private void button_init_2_Click(object sender, RoutedEventArgs e)
{
try
{
javaapplication.NewJPanel newJPanel = new javaapplication.NewJPanel();
//this.stackPanel2.Children.Add(newJPanel);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
}
}