From: Robert W. B. <rb...@di...> - 2001-03-23 21:27:38
|
On Sat, 24 Mar 2001, cindy wrote: > "Robert W. Bill" wrote: > > > My guess is no. Seeing code would help in the case of those errors. > > Here is the code. > > from pawt import swing > import java > import java.awt > > class Mytest: > self.aFrame = swing.JFrame('MY TEST') > self.theKit = self.aFrame.getToolkit() > self.wndSize = self.theKit.getScreenSize() > > self.aFrame.setBounds(self.wndSize.width/4, self.wndSize.height/4, > self.wndSize.width/2, > self.wndSize.height/2) > self.aFrame.setBackground(java.awt.Color.green) > self.aFrame.show(). > > if __name__ == '__main__': > aMyTest = MyTest() > > Thanks for looking at the code. > Wayne Thanks for forwarding the code Wayne. This is an interesting snippet to look at because of the JFrame. One glitch is "self" being used when there's no instance methods defined. Your previous description of how the code works means this is just an omission while transferring code into the mail, so let's assume all the "self.something" lines are in def __init__(self): The real catch is JFrame. Here's what I mean: -A JFrame should close when you click the window close box, but it does _not_ exit the interpreter when you close the last JFrame. You must explicitly add a WindowListener for the window exit event which calls System.exit. The code example below adds a simple exit class that takes care of this. Without the windowListnener, you must use Ctrl-D to exit your example as noted in your previous post. -When using a JFrame you actually work with the content pane. Note the use of "contentPane" in the code below. The getContentPane and setContentPane methods may also be useful for you. With your example this means that the background (green) stays visible when it is set in the contentPane as opposed to blinking green as it previously did. Here's the revised code that should be closer to what you want: --------------------------------------------------------------- from pawt import swing import java class MyTest: def __init__(self): self.aFrame = swing.JFrame('MY TEST', visible=1) self.theKit = self.aFrame.getToolkit() self.wndSize = self.theKit.getScreenSize() self.aFrame.setBounds(self.wndSize.width/4, self.wndSize.height/4, self.wndSize.width/2, self.wndSize.height/2) #WindowListener needed- jvm will not exit without this self.aFrame.addWindowListener(exit()) #Use contentPane to change background color correctly self.aFrame.contentPane.setBackground( java.awt.Color.green) self.aFrame.show() class exit(java.awt.event.WindowAdapter): def windowClosing(self, event): java.lang.System.exit(0) if __name__ == '__main__': aMyTest = MyTest() --------------------------------------------------------------- Cheers, Robert |