Last active
December 20, 2015 16:38
-
-
Save jjam3774/6162523 to your computer and use it in GitHub Desktop.
Basic Example of what Jython can do with Swing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/jython | |
from java.awt.event import ActionListener | |
from java.awt import * | |
from java.lang import Runnable | |
from javax.swing import * | |
import os | |
class mainWindow(Runnable): | |
def __init__(self): | |
self.frame = JFrame("Tools", defaultCloseOperation = JFrame.EXIT_ON_CLOSE) | |
self.frame.setSize(300, 350) | |
self.frame.setLayout(BorderLayout()) | |
self.panel = JPanel() | |
self.panel.setBorder(BorderFactory.createEtchedBorder()) | |
self.panel.setLayout(GridLayout(0,1)) | |
#self.panel.setPreferredSize(100, 50) | |
self.text = JTextArea() | |
###################################################################### | |
# Define Scrollbar | |
###################################################################### | |
scroll = JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) | |
###################################################################### | |
# Set text panel to be displayed from scrollbar | |
###################################################################### | |
scroll.viewport.view = self.text | |
###################################################################### | |
# Define the buttons and the action that they will perform once they have been clicked | |
##################################################################### | |
button = JButton("FILES", actionPerformed=self.bios) | |
button1 = JButton("NET",actionPerformed=self.net) | |
button2 = JButton("MOUNTS",actionPerformed=self.stats) | |
button3 = JButton("DMI",actionPerformed=self.sys) | |
#button.addActionListener(bios()) | |
#button1.addActionListener(processes()) | |
# Add Scrollbar to frame | |
self.frame.add(scroll, BorderLayout.CENTER) | |
self.panel.add(button) | |
self.panel.add(button1) | |
self.panel.add(button2) | |
self.panel.add(button3) | |
self.frame.add(self.panel, BorderLayout.SOUTH) | |
def run( self ) : | |
self.frame.show() | |
def bios(self, event): | |
print("BIOS IS FUNCTIONING") | |
self.text.append(os.popen('ls').read()) | |
def net(self, event): | |
print("NET IS FUNCTIONING") | |
self.text.append(os.popen('ifconfig').read()) | |
def stats(self, event): | |
print("MOUNTS IS FUNCTIONING") | |
self.text.append(os.popen('df -h').read()) | |
def sys(self, event): | |
print("SYS IS FUNCTIONING") | |
self.text.append(os.popen('dmidecode').read()) | |
SwingUtilities.invokeLater(mainWindow()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment