Java Settings Menu - java

I am curently working on a GUI and when clicking a certain button:
settingsB.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
System.out.println("Settings");
}
});
Instead of just printing it there should a new window open where you can adjust settings with sliders textboxes, ... How would you approach that? With new classes or all inside the action listener?
Edit:
My "current solution" is based on the great suggestion from user Holger to call a method showSettingsDialogue():
private void showSettingsDialogue() {
if(settingsOpen) {
return;
}
else {
settingsOpen = true;
settingWindow = new SettingsWindow();
settingWindow.addWindowListener(new WindowListener() {
#Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowClosed(WindowEvent e) {
settingsOpen = false;
}
#Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
});
}
Unfortunally with this way I have to write down even unimplemented methods. Any bether solution then this?

Related

subscribeOn has no effect when creating new Observables [duplicate]

I am using rxjava in eclipse. I cretaed the below posted example.
the issue is,, when i run the code, I receive only
onSubscribe: 0
and I dont receive any output from onNext.
please let me know why I do not receive any output from onNext, and how to fix it
code:
public static void main(String[] args) {
Observable<String> stringObservable = Observable.just("Hello from just Operator1");
stringObservable
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io())
.subscribe(new Observer<Object>() {
#Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("onComplete: OK");
}
#Override
public void onError(Throwable arg0) {
// TODO Auto-generated method stub
}
#Override
public void onNext(Object arg0) {
// TODO Auto-generated method stub
System.out.println("onNext: " + (String) arg0);
}
#Override
public void onSubscribe(Disposable arg0) {
// TODO Auto-generated method stub
System.out.println("onSubscribe: " + arg0);
}
});
}

WebSocket Connection for xmpp

I am trying to establish a websocket connection with port:5280,but unable to connect(server is not listening).
public static WebSocketClient cc;
public static void main(String[] args) throws URISyntaxException
{
cc=new WebSocketClient(new URI("ws://localhost:5280"))
{
#Override
public void onOpen(ServerHandshake arg0)
{
// TODO Auto-generated method stub
System.out.println("onOpen" +arg0);
}
#Override
public void onMessage(String arg0)
{
// TODO Auto-generated method stub
System.out.println("onMessage");
}
#Override
public void onError(Exception arg0)
{
// TODO Auto-generated method stub
System.out.println("onError");
}
#Override
public void onClose(int arg0, String arg1, boolean arg2)
{
// TODO Auto-generated method stub
System.out.println("onClose");
}
};
cc.connect();
Above one is working with new URI("ws://localhost:8887/8080/5120") but having some problem with port no-5280.
Give me any Fix??

how can understand that the DJ native swing jwebbrowser has been completely load the web page?

I want to execute my javascript code in DJ native swing jwebbrowser, but I should wait for the page loading, how can I set listener for it?
I try the following, but after loading it always run the script also it operate late!
webBrowser.addWebBrowserListener(new WebBrowserListener(){
#Override
public void commandReceived(WebBrowserCommandEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void locationChangeCanceled(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void locationChanged(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void locationChanging(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void statusChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
if(webBrowser.getLoadingProgress() == 100)
webBrowser.executeJavascript("some js code");");
}
#Override
public void titleChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowClosing(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
frame.dispose();
}
#Override
public void windowOpening(WebBrowserWindowOpeningEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowWillOpen(WebBrowserWindowWillOpenEvent arg0) {
// TODO Auto-generated method stub
}
});
what should i do?
I should override loadingProgressChanged(WebBrowserEvent arg0) not statusChanged(WebBrowserEvent arg0)
#Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
if(webBrowser.getLoadingProgress() == 100)
webBrowser.executeJavascript("some js code");
}
but still it takes time to load my html!

Android App StartApp Ads Error

I made a game and used an ads company on it (StartApp). I wanna use Interstitial Ads on it. I followed the step they show but can't achieve it. I'm getting error. Here is the LogCat:
http://i.stack.imgur.com/SaIXE.png
Here is the codes:
GameActivity.java
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException
{
StartAppAd.init(this, "10254544", "20454573");
}
MenuScene.java
private StartAppAd startAppAd = new StartAppAd(activity);
#Override
public void createScene() {
startAppAd.showAd();
startAppAd.loadAd();
}
Check the Manifest.xml file. Be sure you wrote the right package name in there.
Try This code and u should update manifest file also
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StartAppSearch.showSearchBox(this);
StartAppAd.init(this, "107181003", "211487617");
StartAppSearch.init(this, "107181003", "211487617");
btnnext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startAppAd.showAd(); // show the ad
startAppAd.loadAd(); //load next add
Intent intent=new Intent(getApplicationContext(),Second.class);
startActivity(intent);
}
});
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
boolean _active = true;
}
return true;
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
startAppAd.onPause();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
startAppAd.onResume();
}
#Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
private StartAppAd startAppAd = new StartAppAd(this);
#Override
public void onBackPressed() {
startAppAd.onBackPressed();
super.onBackPressed();
}
and update in manifest file also
You can not use the
startAppAd.showAd();
startAppAd.loadAd();
inside the Scene class (MenuScene). Instead you can try below method.
In GameActivity class you must be having KeyEvent method. put the code to show the startApp ads in there as below,
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if(SceneManager.getInstance().getCurrentSceneType().toString() == "SCENE_MENU"){
try{
startAppAd.showAd(); // show the ad
startAppAd.loadAd(); // load the next ad
}catch(Exception e){
}
}
try{
SceneManager.getInstance().getCurrentScene().onBackKeyPressed();
}catch(Exception e){
}
}
return false;
}
Regards,
Deepak

How to read data from finger print reader and convert into image file in java

i have to read data from finger print reader and convert into image file. I am using Digital Persona 's device U and U 4500 with Platinum SDK . I am new biometric field. Till now I am only able to detect the device means whether it is connected to system or not.Please guide me what should i do to accomplish this task
i have used this Code(only to check whether device is working )
import com.digitalpersona.onetouch.DPFPGlobal;
import com.digitalpersona.onetouch.DPFPSample;
import com.digitalpersona.onetouch.capture.DPFPCapture;
import com.digitalpersona.onetouch.capture.event.DPFPDataEvent;
import com.digitalpersona.onetouch.capture.event.DPFPDataListener;
import com.digitalpersona.onetouch.capture.event.DPFPErrorEvent;
import com.digitalpersona.onetouch.capture.event.DPFPErrorListener;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusAdapter;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusEvent;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusListener;
import com.digitalpersona.onetouch.capture.event.DPFPSensorEvent;
import com.digitalpersona.onetouch.capture.event.DPFPSensorListener;
public class Demo {
public static void main(String args[]){
//byte[] a=null;
DPFPCapture capture=DPFPGlobal.getCaptureFactory().createCapture();
capture.addReaderStatusListener(new DPFPReaderStatusListener() {
#Override
public void readerDisconnected(DPFPReaderStatusEvent arg0) {
//TODO Auto-generated method stub
System.out.println("I m Dis-connected");
}
#Override
public void readerConnected(DPFPReaderStatusEvent arg0) {
// TODO Auto-generated method stub
System.out.println("I m connected");
}
});
capture.addSensorListener(new DPFPSensorListener() {
#Override
public void imageAcquired(DPFPSensorEvent arg0) {
// TODO Auto-generated method stub
System.out.print("acquired");
}
#Override
public void fingerTouched(DPFPSensorEvent arg0) {
// TODO Auto-generated method stub
System.out.print("s");
}
#Override
public void fingerGone(DPFPSensorEvent arg0) {
// TODO Auto-generated method stub
System.out.print("gone");
}
});
capture.startCapture();
capture.addDataListener(new DPFPDataListener() {
#Override
public void dataAcquired(DPFPDataEvent arg0) {
// TODO Auto-generated method stub
DPFPSample sample=DPFPGlobal.getSampleFactory().createSample();
sample=arg0.getSample();
byte a[]=sample.serialize();
for(byte i:a){
System.out.print(i);
}
}
});
capture.addErrorListener(new DPFPErrorListener() {
#Override
public void exceptionCaught(DPFPErrorEvent arg0) {
// TODO Auto-generated method stub
System.out.println("error");
}
#Override
public void errorOccured(DPFPErrorEvent arg0) {
// TODO Auto-generated method stub
System.out.println("error");
}
});
}
}
I am also currently working on a Digital Persona Finger Print Reader, I actually had the same Problem but now i have overcome it,
I think the code to add the Listeners should be in the init() method and also start the init method in the constructor of the class
The main method should only instantiate the Class.

Categories