def instReg(): global frame global tfName global tfPhone global taAddress global tfAdminLoginId global tfAdminPassword frame = JFrame("Registration Form ") frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.setSize(500,550) frame.setLocation(200,200) frame.setLayout(None) frame.setVisible(True) panel = JPanel() panel.setSize(500,550) panel.setLocation(0,0) panel.setLayout(None) panel.setBackground(Color.LIGHT_GRAY) heading = JLabel("Institute Registration Form ") heading.setBounds(200,30,150,30) lbName = JLabel("Name") lbPhone =JLabel("Phone no ") lbAddress = JLabel("Address") lbAdminLoginId = JLabel("Admin login ") lbAdminPassword =JLabel("Admin Password") font = Font("Courier",Font.PLAIN,16) tfName = JTextField() tfPhone = JTextField() taAddress =JTextArea() tfAdminLoginId = JTextField() tfAdminPassword = JTextField() lbName.setBounds(70,100,150,40) lbPhone.setBounds(70,150,150,40) lbAddress.setBounds(70,200,150,40) lbAdminLoginId.setBounds(70,310,150,40) lbAdminPassword.setBounds(70,360,150,40) tfName = JTextField() tfPhone = JTextField() taAddress = JTextArea() tfAdminLoginId = JTextField() tfAdminPassword = JTextField() tfName.setBounds(250,100,200,40) tfPhone.setBounds(250,150,200,40) taAddress.setBounds(250,200,200,100) tfAdminLoginId.setBounds(250,310,200,40) tfAdminPassword.setBounds(250,360,200,40) tfName.setFont(font) tfPhone.setFont(font) taAddress.setFont(font) tfAdminLoginId.setFont(font) tfAdminPassword.setFont(font) sp = JScrollPane(taAddress) c = frame.getContentPane() btnSave = JButton("Save",actionPerformed=clickAdminReg) btnSave.setBounds(350,420,80,30) #panel.add(lbName) #panel.add(lbPhone) #panel.add(lbAddress) #panel.add(lbAdminLoginId) #panel.add(lbAdminPassword) #panel.add(tfName) #panel.add(tfPhone) #panel.add(c) #panel.add(tfAdminLoginId) #panel.add(tfAdminPassword) #panel.add(btnSave) #panel.add(btnLogin) c.add(lbName) c.add(lbPhone) c.add(lbAddress) c.add(lbAdminLoginId) c.add(lbAdminPassword) c.add(tfName) c.add(tfPhone) c.add(taAddress) c.add(tfAdminLoginId) c.add(tfAdminPassword) c.add(btnSave) frame.add(c)
class ConsolePanel(Panel): def __init__(self): self.console = None self.outText = None self.inText = None self.outTextScroller = None self.nestedInputPanel = None self.directoryText = None Panel.__init__(self, "insets 0 0 0 0") def sendCommand(self, command): print str(self) oldText = self.inText.getText() self.inText.setText(command) self.inText.getActionListeners()[0].actionPerformed(None) self.inText.setText(oldText) def setDirectoryText(self, dirText): self.directoryText.setText(dirText) self.nestedInputPanel.revalidate() def write_out(self,text): if not self.outText: return self.outText.setText(self.outText.getText() + text) def initUI(self): font = Font("Courier New", Font.BOLD, 14) #create the output text panel self.outText = JTextArea() self.outText.setEditable(False) self.outText.setFont(font) self.outText.setWrapStyleWord(True) self.outText.setLineWrap(True) #self.outText.setLineWrap(True) #self.outText.setWrapStyleWord(True) class NoGhostScroller(JScrollPane): def paintComponent(self, g): g.setColor(self.getBackground()) g.fillRect(0, 0, self.getWidth(), self.getHeight()) #super(NoGhostScroller, self).paintComponent(g) self.outTextScroller = JScrollPane(self.outText) self.outTextScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) self.outTextScroller.getVerticalScrollBar().setForeground(Color(255, 0, 0)) #self.outText.setOpaque(False) self.outText.setBackground(Color(0, 20, 0)) self.outText.setForeground(Color.WHITE) #self.outTextScroller.setOpaque(False) self.outTextScroller.setBackground(Color(0, 20, 0)) #self.outText.repaint() #self.layered = JLayeredPane() #self.layered.setLayer(self.outTextScroller, 0) #create the input text box self.inText = JTextField() self.inText.setFocusTraversalKeysEnabled(False) self.inText.setFont(font) self.inText.setBackground(Color(0, 20, 0)) self.inText.setForeground(Color.WHITE) self.inText.getCaret().setVisible(True) self.inText.getCaret().setBlinkRate(500) self.inText.setCaretColor(Color(200,255,200)) class InFocusAdapter(FocusAdapter): def focusLost(adap, e): self.inText.setVisible(True) self.inText.addFocusListener(InFocusAdapter()) self.nestedInputPanel = Panel("Insets 0 0 0 0") #create the directory text box self.directoryText = JTextField() self.directoryText.setEditable(False) self.directoryText.setFont(font) self.directoryText.setBackground(Color(0, 20, 0)) self.directoryText.setForeground(Color.WHITE) #set up the console sys.stdout = FakeOut(self.outText) self.console = BashED_Console(stdout=sys.stdout) self.directoryText.setText(self.console.get_prompt()) self.revalidate(); dirTex = self.directoryText; #create the listener that fires when the 'return' key is pressed class InputTextActionListener(ActionListener): def __init__(self,parent,inp,out,console): self.parent = parent self.inp = inp self.out = out self.console = console def actionPerformed(self, e): #print self.getCommandText() # print(self.console.get_prompt()) # self.console.onecmd(self.inp.getText()) # self.parent.write_out("\n" + self.inp.getText()) # dirTex.setText(self.console.get_prompt()) # self.inp.setText("") self.parent.write_out(self.console.get_prompt() + self.inp.getText() + '\n') if 'clear' in self.inp.getText().split(' ')[0]: self.out.setText("") #clear the screen else: self.console.onecmd(self.inp.getText()) dirTex.setText(self.console.get_prompt()) self.inp.setText("") #create the listener that fires whenever a user hits a key class InputKeyActionListener(KeyAdapter): def __init__(self,parent,inp,out,console): self.parent = parent self.inp = inp self.out = out self.console = console def keyReleased(self, k): inp = self.inp.getText() if k.getKeyCode() == 9: #tab character autos = self.console.tabcomplete(self.inp.getText()) if len(autos) == 1: self.inp.setText(autos[0]) else: i = 0 for option in autos: self.parent.write_out(option) if i % 3 == 0: print('\n') else: print('\t') hist = None if k.getKeyCode() == 38: hist = self.console.next_hist() if k.getKeyCode() == 40: hist = self.console.last_hist() if hist: self.inp.setText(hist.rstrip('\n'))#prevent from firing self.inText.addActionListener(InputTextActionListener(self,self.inText,self.outText,self.console)) self.inText.addKeyListener(InputKeyActionListener(self,self.inText,self.outText,self.console)) def addUI(self): self.add(self.outTextScroller, "cell 0 0, push, grow") self.add(self.nestedInputPanel, "cell 0 1, pushx, growx") self.nestedInputPanel.add(self.directoryText, "cell 0 0") self.nestedInputPanel.add(self.inText, "cell 1 0, spanx, pushx, growx")
class ConsolePanel(Panel): def __init__(self): self.console = None self.outText = None self.inText = None self.outTextScroller = None self.nestedInputPanel = None self.directoryText = None Panel.__init__(self, "insets 0 0 0 0") def sendCommand(self, command): print str(self) oldText = self.inText.getText() self.inText.setText(command) self.inText.getActionListeners()[0].actionPerformed(None) self.inText.setText(oldText) def setDirectoryText(self, dirText): self.directoryText.setText(dirText) self.nestedInputPanel.revalidate() def write_out(self, text): if not self.outText: return self.outText.setText(self.outText.getText() + text) def initUI(self): font = Font("Courier New", Font.BOLD, 14) #create the output text panel self.outText = JTextArea() self.outText.setEditable(False) self.outText.setFont(font) self.outText.setWrapStyleWord(True) self.outText.setLineWrap(True) #self.outText.setLineWrap(True) #self.outText.setWrapStyleWord(True) class NoGhostScroller(JScrollPane): def paintComponent(self, g): g.setColor(self.getBackground()) g.fillRect(0, 0, self.getWidth(), self.getHeight()) #super(NoGhostScroller, self).paintComponent(g) self.outTextScroller = JScrollPane(self.outText) self.outTextScroller.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) self.outTextScroller.getVerticalScrollBar().setForeground( Color(255, 0, 0)) #self.outText.setOpaque(False) self.outText.setBackground(Color(0, 20, 0)) self.outText.setForeground(Color.WHITE) #self.outTextScroller.setOpaque(False) self.outTextScroller.setBackground(Color(0, 20, 0)) #self.outText.repaint() #self.layered = JLayeredPane() #self.layered.setLayer(self.outTextScroller, 0) #create the input text box self.inText = JTextField() self.inText.setFocusTraversalKeysEnabled(False) self.inText.setFont(font) self.inText.setBackground(Color(0, 20, 0)) self.inText.setForeground(Color.WHITE) self.inText.getCaret().setVisible(True) self.inText.getCaret().setBlinkRate(500) self.inText.setCaretColor(Color(200, 255, 200)) class InFocusAdapter(FocusAdapter): def focusLost(adap, e): self.inText.setVisible(True) self.inText.addFocusListener(InFocusAdapter()) self.nestedInputPanel = Panel("Insets 0 0 0 0") #create the directory text box self.directoryText = JTextField() self.directoryText.setEditable(False) self.directoryText.setFont(font) self.directoryText.setBackground(Color(0, 20, 0)) self.directoryText.setForeground(Color.WHITE) #set up the console sys.stdout = FakeOut(self.outText) self.console = BashED_Console(stdout=sys.stdout) self.directoryText.setText(self.console.get_prompt()) self.revalidate() dirTex = self.directoryText #create the listener that fires when the 'return' key is pressed class InputTextActionListener(ActionListener): def __init__(self, parent, inp, out, console): self.parent = parent self.inp = inp self.out = out self.console = console def actionPerformed(self, e): #print self.getCommandText() # print(self.console.get_prompt()) # self.console.onecmd(self.inp.getText()) # self.parent.write_out("\n" + self.inp.getText()) # dirTex.setText(self.console.get_prompt()) # self.inp.setText("") self.parent.write_out(self.console.get_prompt() + self.inp.getText() + '\n') if 'clear' in self.inp.getText().split(' ')[0]: self.out.setText("") #clear the screen else: self.console.onecmd(self.inp.getText()) dirTex.setText(self.console.get_prompt()) self.inp.setText("") #create the listener that fires whenever a user hits a key class InputKeyActionListener(KeyAdapter): def __init__(self, parent, inp, out, console): self.parent = parent self.inp = inp self.out = out self.console = console def keyReleased(self, k): inp = self.inp.getText() if k.getKeyCode() == 9: #tab character autos = self.console.tabcomplete(self.inp.getText()) if len(autos) == 1: self.inp.setText(autos[0]) else: i = 0 for option in autos: self.parent.write_out(option) if i % 3 == 0: print('\n') else: print('\t') hist = None if k.getKeyCode() == 38: hist = self.console.next_hist() if k.getKeyCode() == 40: hist = self.console.last_hist() if hist: self.inp.setText(hist.rstrip('\n')) #prevent from firing self.inText.addActionListener( InputTextActionListener(self, self.inText, self.outText, self.console)) self.inText.addKeyListener( InputKeyActionListener(self, self.inText, self.outText, self.console)) def addUI(self): self.add(self.outTextScroller, "cell 0 0, push, grow") self.add(self.nestedInputPanel, "cell 0 1, pushx, growx") self.nestedInputPanel.add(self.directoryText, "cell 0 0") self.nestedInputPanel.add(self.inText, "cell 1 0, spanx, pushx, growx")
btnDivide = JButton("/", actionPerformed=clickBtnDivide) btnDivide.setBounds(301, 101, 100, 80) btnMultiply = JButton("*", actionPerformed=clickBtnMultiply) btnMultiply.setBounds(301, 181, 100, 80) btnSubtract = JButton("-", actionPerformed=clickBtnSubtract) btnSubtract.setBounds(301, 261, 100, 80) btnPlus = JButton("+", actionPerformed=clickBtnPlus) btnPlus.setBounds(301, 341, 100, 80) btnEqual = JButton("=", actionPerformed=clickBtnEqual) btnEqual.setBounds(301, 421, 100, 80) tf = JTextField("") tf.setBounds(0, 0, 400, 100) tf.setHorizontalAlignment(JTextField.RIGHT) font = Font("Courier", Font.BOLD, 30) tf.setFont(font) frame.add(btnDot) frame.add(btnDel) frame.add(btn0) frame.add(btnEqual) frame.add(btn1) frame.add(btn2) frame.add(btn3) frame.add(btn4) frame.add(btn5) frame.add(btn6) frame.add(btn7) frame.add(btn8) frame.add(btn9) frame.add(btnPlus)