Using bluetooth in java - java

I'm attempting to write a Java application that will open up the device it is run on to receiving audio over Bluetooth and then playing that audio.
I looked up the JavaDoc for javax.bluetooth, frankly I'm a little confused by it, but while importing javax.bluetooth it failed to compile, So I'm not sure whats going on.
This is what I have so far if it helps:
import javax.swing.*;
import javax.obex.*;
import javax.bluetooth.*;
public class BluetoothConnection{
public static void main(String[] args) {
DiscoveryListener alpha;
startInquiry(777, alpha);
}
}

Related

How to get Lightrun running in IntelliJ IDEA 2022.3.1?

No matter what I do Lightrun will generate the following error message:
General agent error at jvm_internals.cc:186.
This is my first time using Lightrun.
This is my code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println(new Scanner(System.in).nextInt() + new Scanner(System.in).nextInt());
}
}
The code itself runs perfectly.
I am using IntelliJ IDEA 2022.3.1.
LR doesn’t work on this version. A bit buggy on the ij versions for the past 2 months…

GLCapabilities not importing properly in eclispe OpenGL. Error: java.lang.NoClassDefFoundError: com/jogamp/opengl/GLCapabilitiesImmutable

The Problem
Hi, this is probably me just being super dumb, but the GLCapabilities import isn't functioning for me.
I'm very new to OpenGL, and Java in general, so I've been following a video tutorial on the subject.
**Video Link For Episode 0: https://www.youtube.com/watch?v=etNPl3Dk2XY**\
Video Link For Episode 1: https://www.youtube.com/watch?v=2KmAZ48-M5c
I have downloaded OpenGL and set up all the files in the project just as he goes through
in episode 0. I am using eclipse, same as him. I have also made sure to map the .jar files to the natives folder, so it can run on my OS, like described in the video.
Now at the time stamp 7:33 he launches the program, and an empty screen pops up, as it should.
BUT, for me, I get this error:
Error: Unable to initialize main class org.graphics.Renderer
Caused by: java.lang.NoClassDefFoundError: com/jogamp/opengl/GLCapabilitiesImmutable
I looked at other stack overflow questions and just google searching, but I couldn't find anything specific about this.
My Code
Here is my code for reference:
package org.graphics;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
public class Renderer {
private static GLWindow myscreen = null;
public static void initalize() {
GLProfile.initSingleton();
GLProfile version = GLProfile.get(GLProfile.GL3);
GLCapabilities caps = new GLCapabilities(version);
myscreen = GLWindow.create(caps);
myscreen.setSize(500,500);
myscreen.setResizable(false);
myscreen.setVisible(true);
}
public static void main(String[] args) {
initalize();
}
Hopefully someone can help me.
Thanks in advance. (:

JFrame equivalent for C# handle pointer

I am currently trying to port code from C# to java. In the C# code, the panel.handle part returns an intptr of the current panel. The intptr is then passed to a DLL method. The C# code is the following:
IntPtr Handle = Panel1.Handle;
The same DLL must be used. I have found something using Win32 and JNI but I have not understood how to use it. Does anyone know the java swing equivalent to this method?
Thanks to the link in the comment and some other research I have managed to find the equivalent to the Handle property in c#. Here is what I have done to anyone who is facing the same problem:
import javax.swing.*;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
public class main {
public static void main(String[] args) {
JFrame jFrame = new JFrame();
final HWND hwnd = new HWND(Native.getComponentPointer(jFrame));
System.out.println(hwnd);
}
}
Please Note that this only works with windows machines since only windows have the concept of everything is a window and every window has a handle.

Obtianing output of NeurophStudio - import error (java)

I am trying to abtain the output (for example: cat: 0,988; dog: 0.012) from NeurophStudio using java. The neural net recognises the images well. I found the code below. I get errors in the first two import lines. Does anyone know where I can find/download these packages? I searched through all my directories already and didn't find it.
import org.neuroph.core.NeuralNetwork; // ! error
import org.neuroph.contrib.imgrec.ImageRecognitionPlugin; // ! error
import java.util.HashMap;
import java.io.File;
import java.io.IOException;
public class ImageRecognitionSample {
public static void main(String[] args) {
// load trained neural network saved with Neuroph Studio (specify some existing neural network file here)
NeuralNetwork nnet = NeuralNetwork.load("Neural Networks/Iconnet25-8.nnet"); // load trained neural network saved with Neuroph Studio
// get the image recognition plugin from neural network
ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin)nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from neural network
try {
// image recognition is done here (specify some existing image file)
HashMap<String, Double> output = imageRecognition.recognizeImage(new File("testimage.png"));
System.out.println(output.toString());
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}
source : http://neuroph.sourceforge.net/image_recognition.html
I found the package code here : https://github.com/neuroph/neuroph/tree/master/neuroph-2.9/Core/src/main/java/org/neuroph/core
Problem: this is not downloadable and I will probably need multiple files/entire package.
Does anyone have experience with this? Any solutions?
download neuroph.jar
then locate it to your project
like this
right click on your project
properties
Libraries
add jar/folder
then show the path where you put the neuroph.jar
hope it will help you!!!!

how to attach my mp3 file with generated jar file?

in this code i select mp3 path is "D:/camera.wav". when i make jar file of this code, it play in only my system. please tell me how to add camera.wav file to my project and give that url to my project. because i want same music should play for all systems, even though they don't have that music.
import java.io.File;
import javax.media.Format;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.PlugInManager;
import javax.media.format.AudioFormat;
public class maintest
{
public static void main(String[] args)
{
//float v=1;
Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
Format input2 = new AudioFormat(AudioFormat.MPEG);
Format output = new AudioFormat(AudioFormat.LINEAR);
PlugInManager.addPlugIn("com.sun.media.codec.audio.mp3.JavaDecoder",
new Format[]{input1, input2},
new Format[]{output},
PlugInManager.CODEC );
try
{
Player player = Manager.createPlayer(new MediaLocator(new File("D:/camera.wav").toURI().toURL()));
//player.getGainControl().setLevel(v);
player.start();
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
JMF is .. ancient. it hasn't been maintained/updated for years, so especially if you want to have some "modern" code, JMF is not the best option.
personally, I once created (al be it a simple one) a small mp3 player, using the JLayer library which you can find here
it has plenty of documentation and examples so it shouldn't take too long to get you going.
You need the MP3 Plugin. Or if that doesn't work, this plugin is also a good resource.
You can also use JavaFX for playing MP3's. If you use Netbeans just create a new project and select JavaFX project instaed of a normal Java project

Categories

Resources