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}}
<pre>module winapp ;
<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);
}</pre>
}</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
</pre>
</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()
=={{header|IDL}}==

pro counter, ev
widget_control, ev.top, get_uvalue=tst
tst[1] = tst[1]+1
widget_control, tst[0], set_value="Number of clicks: "+string(tst[1],format='(i0)')
widget_control, ev.top, set_uvalue=tst
end
id = widget_base(title = 'Window Title',column=1)
ld = widget_label(id, value = 'There have been no clicks yet.')
widget_control, /realize, id, set_uvalue=[ld,0]
dummy = widget_button(id,value=' Click Me ',event_pro='counter')
xmanager, "Simple", Id
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(){
=={{header|IDL}}==
text = "There have been " + ((clicks == 0) ? "no clicks yet" : (clicks + " clicks"));
pro counter, ev
label = new JLabel(text);
widget_control, ev.top, get_uvalue=tst
clicker = new JButton("click me");
tst[1] = tst[1]+1
clicker.addActionListener(this);//listen to the button
widget_control, tst[0], set_value="Number of clicks: "+string(tst[1],format='(i0)')
setLayout(new BorderLayout());//handles placement of components
widget_control, ev.top, set_uvalue=tst
add(label,BorderLayout.CENTER);//add the label to the biggest section
end
add(clicker,BorderLayout.SOUTH);//put the button underneath it
setSize(300,200);//stretch out the window
id = widget_base(title = 'Window Title',column=1)
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//stop the program on "X"
ld = widget_label(id, value = 'There have been no clicks yet.')
setVisible(true);//show it
widget_control, /realize, id, set_uvalue=[ld,0]
}
dummy = widget_button(id,value=' Click Me ',event_pro='counter')
public static void main(String[] args){
xmanager, "Simple", Id
new Clicks();//call the constructor where all the magic happens
end
}
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}}
use 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}}
use Gtk '-init';
<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}}
<python>from Tkinter import Tk, Label, Button
<pre>
from Tkinter import Tk, Label, Button


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===
<python>#!/usr/bin/env python
<pre>
#!/usr/bin/env python
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}}==