February 23, 2013
Java transparent widget
Cool widget in java
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.io.File;
import java.net.Socket;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Scanner;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class Status {
public static void main(String[] args) {
final int w = 130;
final int h = 500;
Dimension x = Toolkit.getDefaultToolkit().getScreenSize();
final JDialog d = new JDialog();
d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
d.setUndecorated(true);
d.setSize(w, h);
d.setBackground(new Color(0, 0, 0, 0));
d.setBounds(x.width - w - 20, 20, w, h);
d.setAlwaysOnTop(true);
JLabel l = new JLabel();
l.setBackground(new Color(0, 0, 0, 0));
l.setForeground(new Color(255, 255, 255));
try {
l.setFont(Font.createFont(Font.TRUETYPE_FONT, l.getClass().getResourceAsStream("/consola.ttf")).deriveFont(Font.PLAIN, 13));
} catch (Exception e) {
l.setFont(l.getFont().deriveFont(Font.PLAIN, 13));
e.printStackTrace();
}
l.setBorder(javax.swing.BorderFactory.createMatteBorder(5, 0, 0, 0, new Color(255, 255, 255)));
l.setVerticalAlignment(l.TOP);
l.setHorizontalAlignment(l.LEFT);
d.add(l);
d.setVisible(true);
String user = System.getProperty("user.name");
String os = System.getProperty("os.name");
double ram = 0;
try {
Process p = Runtime.getRuntime().exec("wmic OS get TotalVisibleMemorySize /Value");
Scanner scan = new Scanner(p.getInputStream());
while (scan.hasNext()) {
String temp = scan.nextLine();
//System.out.println(temp);
if (temp.startsWith("TotalVisibleMemorySize")) {
ram = Long.parseLong(temp.split("=")[1]);
//System.out.println("RAM :" + ram);
break;
}
}
} catch (Exception e) {
}
d.addMouseMotionListener(new java.awt.event.MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
d.setBounds(e.getXOnScreen(), e.getYOnScreen(), d.getWidth(), d.getHeight());
}
@Override
public void mouseMoved(MouseEvent e) {
}
});
d.addMouseListener(new java.awt.event.MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON2) {
System.exit(0);
}
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
long itime = Calendar.getInstance().getTimeInMillis();
while (true) {
StringBuilder status = new StringBuilder();
status.append("Current user: ").append(user);
status.append("
------------------");
Calendar c = Calendar.getInstance();
status.append("
Time: ").append(c.get(Calendar.HOUR_OF_DAY)).append(":").append(c.get(Calendar.MINUTE)).append(":").append(c.get(Calendar.SECOND));
status.append("
Date: ").append(c.get(Calendar.DATE)).append("/").append(c.get(Calendar.MONTH) + 1).append("/").append(c.get(Calendar.YEAR));
status.append("
------------------");
status.append("
OS: " + os);
status.append("
Memory: ").append(new DecimalFormat("#.##").format(ram / 1024 / 1024)).append(" GB");
status.append("
------------------");
File[] f = File.listRoots();
long total = 0;
long free = 0;
for (int i = 0; i < f.length; i++) {
total = f[i].getTotalSpace();
free = f[i].getFreeSpace();
if (total > 0) {
long p = (free * 100 / total);
status.append("
").append(f[i].getAbsolutePath().replace(File.separator, "")).append(" ").append(total / 1024 / 1024 / 1024).append(" GB");
status.append("
").append(p).append("% free : ").append(free / 1024 / 1024 / 1024).append(" GB");
}
}
status.append("
------------------");
try {
Socket s = new Socket("www.google.com", 80);
s.getInputStream();
s.setSoTimeout(500);
s.close();
status.append("
Internet: On");
} catch (Exception e) {
status.append("
Internet: Off");
}
status.append("
Uptime: ").append((c.getTimeInMillis() - itime) / 1000).append(" s");
status.append("
------------------");
//status.append("
Geek.Manish");
status.append("");
l.setText(status.toString());
try {
Thread.sleep(1000);
} catch (Exception e) {
}
}
}
}
Subscribe to:
Post Comments (Atom)
I am genuinely thankful to the owner of this website who has shared this fantastic piece of
ReplyDeletewriting at at this time.
Take a look at my blog :: fitness programs for men
Link exchange is nothing else except it is only placing the other person's website link on your page at proper place and other person will also do same in support of you.
ReplyDeletemy website ... tips slow your golf swing down
Your method of explaining everything in this
ReplyDeleteparagraph is really fastidious, all be able to effortlessly understand
it, Thanks a lot.
my homepage - quick belly fat loss tips
Thanks for the auspicious writeup. It actually was a entertainment account it.
ReplyDeleteLook advanced to more delivered agreeable from you!
By the way, how can we communicate?
My page: adjustable dumbbells ironmaster
can not get to work
ReplyDeleteI used to be recommended this blog via my cousin. I'm no longer sure whether or not this put up is written through him as no one else recognise such distinctive about my trouble. You are wonderful! Thanks!
ReplyDeleteMy webpage :: muscle building workout plan
Hi there to all, how is everything, I think every one is getting more from
ReplyDeletethis web site, and your views are nice designed for new viewers.
Feel free to visit my web page :: natural hair loss vitamins
Hello my loved one! I wish to say that this post
ReplyDeleteis amazing, nice written and come with approximately all significant infos.
I'd like to peer more posts like this .
Also visit my web site; joint juice glucosamine
We're not really camsex much to say? The decision by Lowe's, behemoth chain of retail home
ReplyDeleteimprovement and it carries a light over-spray. ExoPC set out on mandated teaching programs.
Ball featured in countless" routine" homicides and mass murders.
My site sex cams