changeset 1:fac1b8f35265

Applet.
author Mikhail Kryshen <mikhail@kryshen.net>
date Sat, 14 Jul 2012 06:32:31 +0400
parents 91ecd24948de
children 1e64a109812f
files Rakefile src/net/kryshen/charamega/ui.mirah
diffstat 2 files changed, 44 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Rakefile	Sat Jul 14 05:46:29 2012 +0400
+++ b/Rakefile	Sat Jul 14 06:32:31 2012 +0400
@@ -1,15 +1,29 @@
 require 'mirah'
+require 'ant'
 require 'rake/clean'
 
 SRC = FileList['src/**/*.mirah']
-CLEAN.include('build/**/*.class')
+
+CLEAN.include 'build/**/*.class'
+CLEAN.include 'dist/*.jar'
 
 task :default => [:compile]
 
 task :compile => SRC do
-  Mirah::compile '-d', 'build', *SRC
+  Mirah::compile '--jvm', '1.6', '-d', 'build', *SRC
 end
 
 task :run => [:compile] do
   sh 'java -cp build:res net/kryshen/charamega/Ui'
 end
+
+task :jar => [:compile] do
+  ant.jar :jarfile => 'dist/charamega.jar' do
+    fileset :dir => 'build'
+    fileset :dir => 'res'
+    manifest do
+      attribute :name => 'Main-Class', :value => 'net.kryshen.charamega.Ui'
+    end
+  end
+end
+
--- a/src/net/kryshen/charamega/ui.mirah	Sat Jul 14 05:46:29 2012 +0400
+++ b/src/net/kryshen/charamega/ui.mirah	Sat Jul 14 06:32:31 2012 +0400
@@ -25,9 +25,12 @@
 import java.net.URI
 
 class Ui < JPanel
-  @@title = 'Charamega'
-  @@version = '0.9'
-  @@home = 'http://kryshen.net/games/'
+
+  def self.initialize:void
+    @@title = 'Charamega'
+    @@version = '0.9'
+    @@home = 'http://kryshen.net/games/'
+  end
 
   def initialize(root_pane:JRootPane)
     super LayoutManager(BorderLayout.new)
@@ -86,6 +89,22 @@
     @field.repaint
   end
 
+  def self.create_frame
+    title = @@title
+    SwingUtilities.invokeLater do
+      # UIManager.setLookAndFeel UIManager.getSystemLookAndFeelClassName
+      
+      frame = JFrame.new title
+      ui = Ui.new(frame.getRootPane)
+      
+      frame.getContentPane.add ui
+      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
+        .setSize(800, 600)
+        .validate
+        .setVisible(true)
+    end
+  end
+
   private
 
   def create_status
@@ -251,13 +270,10 @@
   end
 end
 
-# UIManager.setLookAndFeel UIManager.getSystemLookAndFeelClassName
-
-frame = JFrame.new 'Charamega'
-ui = Ui.new(frame.getRootPane)
+class Applet < JApplet
+  def initialize
+    getContentPane.add Ui.new(getRootPane)
+  end
+end
 
-frame.getContentPane.add ui
-frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
-  .setSize(800, 600)
-  .validate
-  .setVisible(true)
+create_frame