So, what I am looking is a way to call the values that I saved to preferences class that can be called up with the clicking of a radio button after the user has defined and saved their inputs.
Class File used for saving and then trying to recall the saved data.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class CustomConfig
{
public static Properties prop = new Properties();
public void saveProp(String title, boolean value)
{
try
{
prop.setProperty(title,String.valueOf(value));
prop.store(new FileOutputStream("config.radiobutton"),"");
}
catch(IOException e)
{
}
}
public String getProp(String title)
{
String value = title;
try
{
prop.load(new FileInputStream("config.radiobutton"));
value = prop.getProperty(title);
}
catch(IOException e)
{
}
return value;
}
I am then using the following code to try to call the radio button(s) that have been defined by the user.
private void CustomRadioMouseReleased(java.awt.event.MouseEvent evt) {
con.getProp(CalabrioRadio.getText());
System.out.println(con.getProp(CalabrioRadio.getText()));
}
For good measure here is the text as it was saved initially to the config file...
#
#Sun Mar 05 16:09:26 CST 2017
Calabrio=true
CTIOS\ Soft\ Phone=false
Account\ Services=false
Appease=false
Sales\ Ads\ (VMAG)=false
Place\ Order/Oracle=false
Outlook=false
Order\ Status=false
Kronos=false
Collections\ Account\ Services=false
Daily\ Specials=false
HOD\ /\ CCD=false
Intranet\ (AAFES\ Web\ Portal)=false
MyECP.com=false
ShopMyExchange.com=false
The issue that I am currently having it, that with the above code, I can't seem to actually call the values back in to change the Selected state of my radio buttons. When I run the System.out.Println it will however show the correct information. I am at a loss for what to do at this point as far as getting the buttons to show per the info selected by the user and then saved. Any help on what to do at this point would be greatly appreciated.
Please let me know if any further information is needed.
Okay... So I think I finally managed to stumble through to my own answer. I am going to go ahead and post it just in case anyone is having this issue as well.
So, I am going to re-post everything in the order in which it was originally posted, and will comment out where the changes were made.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class CustomConfig
{
public static Properties prop = new Properties();
public void saveProp(String title, boolean value)
{
try
{
prop.setProperty(title,String.valueOf(value));
prop.store(new FileOutputStream("config.radiobutton"),"");
}
catch(IOException e)
{
}
}
public static boolean getProp(String title) // Modified from Original
{
String value = title;
try
{
prop.load(new FileInputStream("config.radiobutton"));
value = prop.getProperty(title);
}
catch(IOException e)
{
}
return Boolean.parseBoolean(value); // Modified from Original
}
}
Next portion will once again be commented on the modified portions.
private void CustomRadioMouseReleased(java.awt.event.MouseEvent evt) {
CalabrioRadio.setSelected(con.getProp(CalabrioRadio.getText()));
// The above line was changed
System.out.println(con.getProp(CalabrioRadio.getText()));
}
With that said, this is working for me now. So, if anyone else is having this issue, I hope this helps in some way.
Related
I'm trying to generate a list of all my saved reddit items using JRAW.
I've gone through the Quickstart , and successfully managed to login and retrieve information, and I can get a list of items on the Frontpage from the Cookbook, but I can't work out how I would get a list of my saved items (comments and posts) or a list of my own posts (also comments and posts).
The saved items are at https://www.reddit.com/user/<username>/saved/, but I don't know how to get jraw to retrieve and parse that, or if the api uses a different URL.
Edit: I think I probably need to use a UserContributionPaginator, but I haven't quite worked out exactly how to get it to work yet.
Worked it out.
package com.jraw;
import net.dean.jraw.RedditClient;
import net.dean.jraw.http.UserAgent;
import net.dean.jraw.http.oauth.Credentials;
import net.dean.jraw.http.oauth.OAuthData;
import net.dean.jraw.http.oauth.OAuthException;
import net.dean.jraw.models.Contribution;
import net.dean.jraw.models.Listing;
import net.dean.jraw.paginators.UserContributionPaginator;
public class printSaved {
public static void main(String [] args) {
UserAgent myUserAgent = UserAgent.of("desktop", "com.jraw.printSaved", "v0.01", "user");
RedditClient redditClient = new RedditClient(myUserAgent);
String username = "username";
Credentials credentials = Credentials.script(username, "<password>", "<clientId>", "<clientSecret>");
OAuthData authData = null;
try {
authData = redditClient.getOAuthHelper().easyAuth(credentials);
} catch (OAuthException e) {
e.printStackTrace();
}
redditClient.authenticate(authData);
UserContributionPaginator saved = new UserContributionPaginator(redditClient,"saved",username);
Listing<Contribution> savedList = saved.next();
for (Contribution item : savedList) {
System.out.println(item);
}
}
}
I am try to open a javadoc html file with my new application, however I can not get the javadoc file to open, I have a class name OpenUri, which when called is supposed to open the javadoc:
package gui;
import java.awt.Desktop;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import javax.swing.JFrame;
public class OpenUri extends JFrame {
public static void openWebpage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void openWebpage(URL url) {
try {
openWebpage(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
I am then calling and using this class from another class called Menu, where the help button has an action listener, etc. However when I run the code and press the help button, no javadoc appears, ie, it doesn't open the document, ie, nothing happens, no window, nothing ?
The only way I can open it is manually, by clicking on it in eclipse, here is the specific code from the Menu class I am Using:
//Help
JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H);
helpMenu.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent event) {
try {
URI uri = new URI("file:///C:/Users/howhowhows/workspace/OPTICS_DROP_MENU/doc/index.html");
OpenUri.openWebpage(uri);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
});
If anyone has any ideas as to what I am doing wrong, ie what I need to add/change, it would be greatly appreciated.
Have you downloaded and tried the demo code from the Swing tutorial on How to Integrate With the Desktop Class.
When I used that code and pasted your URI into the text field no window is displayed and I get a "System cannot find the file" message as expected.
When I then enter a simple URI that I know exists: "c:/java/a.html" the browser opens as expected.
So I suggest you start with known working code and see if your URI works. If it does work then the problem is your code, so compare the working code to your code to see what the difference is. If it doesn't work then the problem is the URI.
If you still have problems then post a proper SSCCE that demonstrates the problem. Given that your OPenURI class extends JFrame for no reason we don't know what other strange things you might be doing in your code.
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException
{
File fis=new File("D:/Testcode/Test.txt");
BufferedReader br;
String input;
String var = null;
if(fis.isAbsolute())
{
br=new BufferedReader(new FileReader(fis.getAbsolutePath()));
while ((input=br.readLine())!=null) {
var=input;
}
}
//String var="Duminy to Warner, OUT, Duminy gets a wicket again. He has been breaking...
if(var!=null)
{
String splitstr[]=var.split(",");
if(splitstr[0].contains("to"))
{
String ss=splitstr[0];
String a[]=ss.split("\\s+");
int value=splitstr[0].indexOf("to");
System.out.println("Subject:"+splitstr[0].substring(0,value));
System.out.println("Object:"+splitstr[0].substring(value+2));
System.out.println("Event:"+splitstr[1]);
int count=var.indexOf(splitstr[2]);
System.out.println("Narrated Information:"+var.substring(count));
}
}
}
}
The above program shown the following output:
Subject:Duminy
Object: Warner
Event: OUT
Narrated Information: Duminy gets a wicket again. He has been breaking....
my question is, the text may contain, For example: "Dumto to Warner, OUT, Duminy gets a wicket again. He has been breaking..." means, the above program wouldn't show output like above.. how to identity the text after the space for checking the condition
Instead of:
if(splitstr[0].contains("to")
Change it to:
if(splitstr[0].contains(" to ")
It should then work fine IMO.
import java.awt.*;
import java.applet.*;
import java.net.*;
/*<applet code=CodeBase width=300 height=300>
</applet>*/
public class CodeBase extends Applet
{
String sn,br;
URL url;
public void start()
{
AppletContext ac=getAppletContext();
url=getCodeBase();
try{
ac.showDocument(new URL(url+"a.html"));
System.out.println("Hello");
// ac.showDocument(new URL("D:Java Programs//Applet//a.html"));
}
catch(MalformedURLException e)
{
showStatus("Url not found");
}
}
}
This code does not show the document of the a.html in applet. When we use AppletContext.showDocument() method then it display the document at the specified URL, but it not worked.
As a first suggestion, change:
ac.showDocument(new URL(url+"a.html"));
To:
ac.showDocument(new URL(url,"a.html"));
But even better, add some sanity checking to the before/after. Something like:
URL urlPlus = new URL(url+"a.html");
System.out.println(urlPlus);
URL urlComma = new URL(url,"a.html");
System.out.println(urlComma);
// ...
That last part is what I refer to as 'sanity check debugging'. It is easier to inspect with an IDE that has a debugger, but failing that use the principle "When in doubt, print out!"
I'm developing a Eclipse plugin that reads from and writes to the console. I expect the following code to flash an alert window with "Hello World" on it.
public void run(IAction action) {
ConsoleCommands.writeToConsole("Hello World!");
Alert(ConsoleCommands.readConsole());
}
However, the alert simply shows blank. Some investigation showed that the read was happening before the write (the display on the console was fine, just the alert was showing the previous state of the console) so I tried,
public void run(IAction action) {
ConsoleCommands.writeToConsole("Hello Wolrd!");
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Alert(ConsoleCommands.readConsole());
}
in case there was a threading issue, but this simply delays the writing to the console as well. Any ideas what is happening?
----EDIT-----
In case it's useful, here's the code for the methods...
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
public class ConsoleCommands {
private static MessageConsole findConsole(String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
return (MessageConsole) existing[i];
// no console found, so create a new one
MessageConsole myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[] { myConsole });
return myConsole;
}
public static String readConsole() {
MessageConsole myConsole = findConsole("Joe's Console");
IDocument doc = myConsole.getDocument();
return doc.get();
}
public static MessageConsole writeToConsole(String output) {
MessageConsole myConsole = findConsole("Joe's Console");
MessageConsoleStream out = myConsole.newMessageStream();
out.println(output);
return myConsole;
}
}
Try writing to the console using myConsole.getDocument().set(output) instead of using the stream.
I don't know if this is recommended practice but it solved the problem for us...