Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14076
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Knute Johnson <nospam@knutejohnson.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Applet code conversion... |
| Date | Tue, 01 May 2012 08:44:04 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 101 |
| Message-ID | <jnp0c4$p3q$1@dont-email.me> (permalink) |
| References | <4f9e356a$0$1390$4fafbaef@reader1.news.tin.it> <jnlo8d$81j$1@news.albasani.net> <4f9f8fdf$0$1387$4fafbaef@reader1.news.tin.it> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Tue, 1 May 2012 15:44:04 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="25722"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Mog1Yir+mYogTyPNWCHjq" |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120420 Thunderbird/12.0 |
| In-Reply-To | <4f9f8fdf$0$1387$4fafbaef@reader1.news.tin.it> |
| Cancel-Lock | sha1:QNkdgexNP4Pi7k76X5C1BJZszDk= |
| Xref | csiph.com comp.lang.java.programmer:14076 |
Show key headers only | View raw
On 5/1/2012 12:28 AM, linus wrote:
> Lew ha scritto:
>> linus wrote:
>>> How an applet code code can be trasformed to an application code ?
>>> I thought that adding a "main" would be enough .... but it is not so
>>> easy ! Is
>>> there an example about this my problem ?
>>
>> Did you try a web search?
>>
>> I found this in five minutes or less:
>> <http://www.johnloomis.org/cpe101/notes/SwingGUI/combined/combined.html>
>>
>> FWIW, my search string was "Java combining an applet and application".
>>
>
> With the code
>
> http://www.johnloomis.org/cpe101/notes/SwingGUI/combined/combined.html
>
> I get >>
>
> :174: width is not public in java.awt.Component; cannot be accessed from
> outside package
> { width = ( w >= 0 ? w : 300 ); }
>
> :177: height is not public in java.awt.Component; cannot be accessed
> from outside package
> { height = ( h >= 0 ? h : 200 ); }
>
>
> Wath have I to do ?
> Many thanks .
>
>
>
>
Linus:
The code you provide does run as an application. Just compile it and
run it. It is however way too complex for the task it is attempting.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends JPanel implements ActionListener {
private String state = "";
public test() {
setPreferredSize(new Dimension(400,300));
}
public void actionPerformed(ActionEvent ae) {
state = ae.getActionCommand();
repaint();
}
public void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(getForeground());
if (state.equals("Line"))
g.drawLine(0,0,getWidth(),getHeight());
else if (state.equals("Oval"))
g.drawOval(0,0,getWidth(),getHeight());
else if (state.equals("Rect"))
g.drawRect(5,5,getWidth()-10,getHeight()-10);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
test t = new test();
JFrame f = new JFrame("test");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.add(t,BorderLayout.CENTER);
JPanel p = new JPanel();
JButton b = new JButton("Line");
b.addActionListener(t);
p.add(b);
b = new JButton("Oval");
b.addActionListener(t);
p.add(b);
b = new JButton("Rect");
b.addActionListener(t);
p.add(b);
f.add(p,BorderLayout.NORTH);
f.pack();
f.setVisible(true);
}
});
}
}
I deliberately left out the random code because I felt like it.
--
Knute Johnson
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Applet code conversion... linus <linus@yahoo.com> - 2012-04-30 08:50 +0200
Re: Applet code conversion... Jeff Higgins <jeff@invalid.invalid> - 2012-04-30 06:06 -0400
Re: Applet code conversion... Lew <noone@lewscanon.com> - 2012-04-30 03:07 -0700
Re: Applet code conversion... linus <linus@yahoo.com> - 2012-05-01 09:28 +0200
Re: Applet code conversion... Knute Johnson <nospam@knutejohnson.com> - 2012-05-01 08:44 -0700
Re: Applet code conversion... linus <linus@yahoo.com> - 2012-05-02 15:45 +0200
Re: Applet code conversion... Knute Johnson <nospam@knutejohnson.com> - 2012-05-02 16:58 -0700
Re: Applet code conversion... Roedy Green <see_website@mindprod.com.invalid> - 2012-05-02 15:51 -0700
Re: Applet code conversion... Tsukino Usagi <usagi@tsukino.ca> - 2012-04-30 20:40 +0900
Re: Applet code conversion... Roedy Green <see_website@mindprod.com.invalid> - 2012-04-30 07:08 -0700
csiph-web