Simple windowed application: Difference between revisions
Content added Content deleted
(+D) |
(Added Java (#100 yay!), alphabetized, added syntax highlighting, libheader for theseus) |
||
Line 4: | Line 4: | ||
{{works with|D|1}} |
{{works with|D|1}} |
||
{{libheader|DFL}} |
{{libheader|DFL}} |
||
< |
<d>module winapp ; |
||
import dfl.all ; |
import dfl.all ; |
||
import std.string ; |
import std.string ; |
||
Line 34: | Line 34: | ||
void main() { |
void main() { |
||
Application.run(new MainForm); |
Application.run(new MainForm); |
||
}</ |
}</d> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
{{works with|Delphi|5.0}} |
{{works with|Delphi|5.0}} |
||
Line 43: | Line 43: | ||
'''NOTE:''' The project name here must match the name of the file. |
'''NOTE:''' The project name here must match the name of the file. |
||
<delphi> |
|||
<pre> |
|||
-- begin file -- |
-- begin file -- |
||
Line 132: | Line 131: | ||
end. // Program |
end. // Program |
||
</ |
</delphi> |
||
=={{header|E}}== |
=={{header|E}}== |
||
{{libheader|Swing}} |
{{libheader|Swing}} |
||
{{works with|E-on-Java}} |
{{works with|E-on-Java}} |
||
when (currentVat.morphInto("awt")) -> { |
when (currentVat.morphInto("awt")) -> { |
||
Line 158: | Line 156: | ||
{{works with|bigFORTH}} |
{{works with|bigFORTH}} |
||
{{libheader|MINOS}} |
{{libheader|MINOS}} |
||
also minos |
also minos |
||
text-label ptr click-label |
text-label ptr click-label |
||
Line 172: | Line 169: | ||
===The same with Theseus=== |
===The same with Theseus=== |
||
{{libheader|Theseus}} |
|||
#! xbigforth |
#! xbigforth |
||
\ automatic generated code |
\ automatic generated code |
||
Line 219: | Line 217: | ||
frame.pack() |
frame.pack() |
||
frame.show() |
frame.show() |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
=={{header|J}}== |
=={{header|J}}== |
||
Line 250: | Line 262: | ||
simpleApp_run<nowiki>''</nowiki> |
simpleApp_run<nowiki>''</nowiki> |
||
=={{header|Java}}== |
|||
{{libheader|AWT}} |
|||
{{libheader|Swing}} |
|||
<java>import java.awt.BorderLayout; |
|||
import java.awt.event.ActionEvent; |
|||
import java.awt.event.ActionListener; |
|||
import javax.swing.JButton; |
|||
import javax.swing.JFrame; |
|||
import javax.swing.JLabel; |
|||
public class Clicks extends JFrame implements ActionListener{ |
|||
private int clicks = 0; |
|||
private JLabel label; |
|||
private JButton clicker; |
|||
private String text; |
|||
public Clicks(){ |
|||
⚫ | |||
text = "There have been " + ((clicks == 0) ? "no clicks yet" : (clicks + " clicks")); |
|||
⚫ | |||
label = new JLabel(text); |
|||
⚫ | |||
clicker = new JButton("click me"); |
|||
⚫ | |||
clicker.addActionListener(this);//listen to the button |
|||
⚫ | |||
setLayout(new BorderLayout());//handles placement of components |
|||
⚫ | |||
add(label,BorderLayout.CENTER);//add the label to the biggest section |
|||
⚫ | |||
add(clicker,BorderLayout.SOUTH);//put the button underneath it |
|||
⚫ | |||
setSize(300,200);//stretch out the window |
|||
⚫ | |||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//stop the program on "X" |
|||
⚫ | |||
setVisible(true);//show it |
|||
⚫ | |||
} |
|||
⚫ | |||
public static void main(String[] args){ |
|||
⚫ | |||
new Clicks();//call the constructor where all the magic happens |
|||
⚫ | |||
} |
|||
public void actionPerformed(ActionEvent arg0) { |
|||
if(arg0.getSource() == clicker){//if they clicked the button |
|||
clicks++; |
|||
text = "There have been " + clicks + " clicks"; |
|||
label.setText(text);//change the text |
|||
} |
|||
} |
|||
}</java> |
|||
=={{header|MAXScript}}== |
=={{header|MAXScript}}== |
||
Line 284: | Line 319: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|Tk}} |
{{libheader|Tk}} |
||
<perl> use Tk; |
|||
$main = MainWindow->new; |
$main = MainWindow->new; |
||
Line 293: | Line 328: | ||
-command => sub { $l->configure(-text => 'Number of clicks: '.(++$count).'.'); }, |
-command => sub { $l->configure(-text => 'Number of clicks: '.(++$count).'.'); }, |
||
)->pack; |
)->pack; |
||
MainLoop(); |
MainLoop();</perl> |
||
{{libheader|GTK}} |
{{libheader|GTK}} |
||
<perl> use Gtk '-init'; |
|||
# Window. |
# Window. |
||
Line 322: | Line 357: | ||
# Main loop. |
# Main loop. |
||
Gtk->main; |
Gtk->main;</perl> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{libheader|Tkinter}} |
{{libheader|Tkinter}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
def update_label(): |
def update_label(): |
||
Line 340: | Line 374: | ||
l.pack() |
l.pack() |
||
Button(w, text="click me", command=update_label).pack() |
Button(w, text="click me", command=update_label).pack() |
||
w.mainloop() |
w.mainloop()</python> |
||
</pre> |
|||
===The same in OO manner=== |
===The same in OO manner=== |
||
⚫ | |||
<pre> |
|||
⚫ | |||
from Tkinter import Button, Frame, Label, Pack |
from Tkinter import Button, Frame, Label, Pack |
||
Line 365: | Line 397: | ||
if __name__=="__main__": |
if __name__=="__main__": |
||
ClickCounter().mainloop() |
ClickCounter().mainloop()</python> |
||
</pre> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |