Easily done via Java Toolkit
StringSelection selection = new StringSelection(theString);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Monday, May 02, 2016
commenting a line in Netbeans
commenting a line in Netbeans ? Try this
Ctrl + Shift + C
Source : https://netbeans.org/project_downloads/usersguide/shortcuts-80.pdf
Ctrl + Shift + C
Source : https://netbeans.org/project_downloads/usersguide/shortcuts-80.pdf
Monday, June 11, 2012
Auto-Format, Visual Studio
- CTRL-A to select the whole text.
- Ctrl+K- Ctrl + F
- Ctrl+K- Ctrl + F
Before Auto Format
Ctrl - A selects the whole text
Ctrl K + Ctrl F, auto formats the whole text
Tuesday, April 19, 2011
start jFrame in the center of the screen
// Get the size of the screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
// Determine the new location of the window
int w = window.getSize().width;
int h = window.getSize().height;
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;
// Move the window
window.setLocation(x, y);
Monday, April 18, 2011
Integrating power of Java & Processing :-)
In the following link you can find how to import processing libraries to a Java class where you can combine the power of Java with the flexibility of Processing and make miracles ;-)
http://processing.org/learning/eclipse/
Source : Processing.org
http://processing.org/learning/eclipse/
Source : Processing.org
Thursday, March 03, 2011
Android & WiFi information, Wifimanager + Wifiinfo
For having access to the WiFi connection, you can use the WifiManager and WifiInfo classes in Android SDK. The following code can show you how you can do get access to things like your IP address, the connected network name or the available networks around you :
*** VERY IMPORTANT : To use this you need to add couple of lines to android manifest(XML file -> AndroidManifest.xml).
WifiManager myWifiMananger = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo myNetInfo = myWifiMananger.getConnectionInfo();
showIp.append(changeIp(myNetInfo.getIpAddress()) + " \n");
showIp.append(myNetInfo.getSSID() + " ");
List<ScanResult> scanList = myWifiMananger.getScanResults();
for(ScanResult element : scanList){
showIp.append(element.SSID + " Level: " + element.level + " freq : " + element.frequency + " Cap: " + element.capabilities + "\n");
}
//DONT forget that the getIpAddress returns an int value. Convert it to string :
public String changeIp(int ipAddress){
return String.format("%d.%d.%d.%d",
(ipAddress & 0xff),
(ipAddress >> 8 & 0xff),
(ipAddress >> 16 & 0xff),
(ipAddress >> 24 & 0xff));
}
*** VERY IMPORTANT : To use this you need to add couple of lines to android manifest(XML file -> AndroidManifest.xml).
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
Tuesday, March 01, 2011
Tuesday, February 15, 2011
Convert array of strings to a list, C#
It is very easy to convert an array of string to a list in C-sharp :
// this line returns an array of file names
string[] fileEntries = Directory.GetFiles("c:/test");
List fileList = new List(fileEntries.Length);//convert an array to List
// this line returns an array of file names
string[] fileEntries = Directory.GetFiles("c:/test");
List
Labels:
.NET,
C#,
programming,
windows,
windows programming
Thursday, January 13, 2011
String & Javascript
String in Javascript, cool link : http://www.javascriptkit.com/javatutors/string4.shtml
Javascript, forward to another page according to the refferer URL
<!-- Hide script from old browsers<br>
if (document.referrer.indexOf("facebook") != -1)
//document.write("From facebook")
location.href = "www.yourpage.com";
else
document.write("Not from facebook so we stay on this page")
//-- Stop hiding script -->
if (document.referrer.indexOf("facebook") != -1)
//document.write("From facebook")
location.href = "www.yourpage.com";
else
document.write("Not from facebook so we stay on this page")
//-- Stop hiding script -->
Monday, January 10, 2011
KeyListener in Java
If you want to write a code in Java which is based on keys being pressed on keyboard, then KeyListener is your way a head. This link at Oracle.com has a very nice description of the whole class and a very good example :
http://download.oracle.com/javase/tutorial/uiswing/events/keylistener.html
http://download.oracle.com/javase/tutorial/uiswing/events/keylistener.html
Friday, January 07, 2011
HOWTO : add/remove a String Item to jComboBox, Java
jComboBox :
// Add an item to the start of the list
cb.insertItemAt("item0", 0);
// Add an item after the first item
cb.insertItemAt("item0.5", 1);
// Add an item to the end of the list
cb.addItem("item3");
// Remove first item
cb.removeItemAt(0);
// Remove the last item
cb.removeItemAt(cb.getItemCount()-1);
// Remove all items
cb.removeAllItems();
HOWTO : get a list of available ports, Java
If you want to ahve a list over all ports, the code down here can help alot
protected void list() {
// get list of ports available on this particular computer,
// by calling static method in CommPortIdentifier.
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
// Process the list.
while (portList.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier) portList.nextElement();
System.out.print("Port " + cpi.getName() + " ");
if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println("is a Serial Port: " + cpi);
} else if (cpi.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
System.out.println("is a Parallel Port: " + cpi);
} else {
System.out.println("is an Unknown Port: " + cpi);
}
}
}
Source : java2s.com, modified as javax.comm does not exist anymore on Windows and RxTx should be used
Monday, December 27, 2010
How to Group your Radio Buttons
First add your Radio Buttons to the panel and then select all radio buttons you want to group and set their buttonGroup property (choose the group name from the combo box).
Tuesday, October 19, 2010
How to find an element in a List and return the index, Python
Check if value exist in a list, L ?
if value in L:
print "list contains", value
Returns the index, where value exist in List, L :
if value in L:
print "list contains", value
Returns the index, where value exist in List, L :
i = L.index(value)
Array of classes in Python
b = [bullet() for x in range(50)]
Reverse a string, Python
def reverseString(s):
"""Reverses a string given to it."""
return s[::-1]
"""Reverses a string given to it."""
return s[::-1]
Python string manipulation problem
In python string are immutable so if you want to just change a character in a string you get following error :
>>>> idx = 1
>>>> s1 = "pxthon"
>>>> s1[idx] = 'y'
> Traceback (most recent call last):
> File "", line 1, in ?
> TypeError: object does not support item assignment
But you can always go for a way out which is not pretty and can lead to some problems if you are not careful, but works :
s1 = s1[0:idx] + 'y' + s1[idx+1:]
>>>> idx = 1
>>>> s1 = "pxthon"
>>>> s1[idx] = 'y'
> Traceback (most recent call last):
> File "
> TypeError: object does not support item assignment
But you can always go for a way out which is not pretty and can lead to some problems if you are not careful, but works :
s1 = s1[0:idx] + 'y' + s1[idx+1:]
How to append a dictionary in Python
groups = {'IRISH' : 'green', 'AMERICAN' : 'blue'}
# if you want to later add a new one, i.e., 'ITALIAN' : 'orange'
groups['ITALIAN'] = 'orange'
# if you want to later add a new one, i.e., 'ITALIAN' : 'orange'
groups['ITALIAN'] = 'orange'
Python for Java Programmers
If you are a Java programmer and need to learn python, try this link. It is pretty useful.
Subscribe to:
Comments (Atom)