プログラム板で質問したのですが、分かる人がいませんでした。 Eclipseを使用しJSPを入力し、Tomcatを立ち上げた上でアクセスすると なぜか、 ?? The server encountered an internal error () that prevented it from fulfilling this request.
public class Test extends JApplet implements ActionListener { public void init() { JButton button = new JButton("Kitty on your lap"); button.addActionListener(this);
この様なプログラミングをJavaではよく見かけますが、この場合、JBottunク ラスのメソッドaddActionListenerの引数はどうなってるんですか? public void addActionListener(ActionListener al){} となってるんですかね?
108 :仕様書無しさん:05/02/27 21:12:37
/** * Adds an <code>ActionListener</code> to the button. * @param l the <code>ActionListener</code> to be added */ public void addActionListener(ActionListener l) { listenerList.add(ActionListener.class, l); }
まずは簡単なのから void foo( ArrayList a ){} というメソッドでは Vector で呼べない。 void foo( List a ){} にしておけば ArrayListでも Vector でもよべる。ここまではわかるな?
で、 class A { String getName(){ return name; } } というようなクラスがあったとして、そいつらを名前順でソートする関数を一生懸命つくったとする。 で、あとから class B { String getName(){ return name; } } というクラスを作ったとする。こいつは内容は A とまったく同じだが、AとBは何の関連もないことになる。 そーすると、さっき作った A の名前でソートする関数は B にはつかえないわけだ。
そーゆーときに getName() をもつインターフェースをつくってそれを実装する形にしておけば、 A でも B でもイケる名前でソートメソッドがつくれるわけだ。
String x = "Hello" ; int y = 9; x += y; String x = "Hello" ; int y = 9; if (x == y) { } String x = "Hello" ; int y = 9; x = x + y; String x = "Hello" ; int y = 9; y = y + x; String x = null;int y = (x != null) && (x.length( ) > 0) ? x.length( ) : 0;
1.String x = "Hello" ; int y = 9; x += y; 2.String x = "Hello" ; int y = 9; if (x == y) { } 3.String x = "Hello" ; int y = 9; x = x + y; 4.String x = "Hello" ; int y = 9; y = y + x; 5.String x = null;int y = (x != null) && (x.length( ) > 0) ? x.length( ) : 0;
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); panel = new Vector ();
for ( int i=0; i<layer.size(); i++ ) { Object l = layer.elementAt(i); if ( l instanceof LayerRGBT) { JPanel jp = new JPanel(); //Color c = new Color(1,1,1); ←これがエラー jp.setBackground(c); panel.addElement(jp); } } } }
class Outer { int o; static class Inner { Outer o = new Outer(); int i = o.o; } public static void main(String[] args) { System.out.println(new Outer.Inner().i); } } 自分の勘違いでなければこんな感じです。
class Nyuuryoku { public static void main(String args[]) { InputStreamReader n = new InputStreamReader(System.in); try{ int m = n.read(); System.out.println( (char)m); } catch (IOException e){} } }
JTable table = new JTable(); JTextField text = new JTextField(); text.setFont(font); DefaultCellEditor cellEditor = new DefaultCellEditor(text); table.setCellEditor(cellEditor);
StringBuffer buf = new StringBuffer(); for (int i = 0; i < javaListNum; i++) { buf.append(",!"); } if (buf.length > 0) buf.removeCharAt(0); javaList.add(buf.toString());
ということでまずは全要素を "!" にする。 for (int i = 0; i < javaListNum; ++i) javaList.set(i, "!");
で、javaList の中身をカンマ区切りで出力する。 for (int i = 0; i < javaListNum; ++i) { if (i > 0) System.out.print(','); System.out.print(javaList.get(i)); } System.out.println();
>>445 MAX_VALUE とかは、何の MAX かわからなくなるのでやらないな クラス名なしでも意味のわかるもの (sin cos とか parseInt とか) だけにしてる
447 :仕様書無しさん:2008/06/28(土) 23:27:56
http://www.objectstart.com/downloads.html にある下から2番目のClick here to access a Zip file containing the Java 1.5.x version of source code for the second edition of BJO. (This version of source code will not compile with Java 1.4.x or earlier compilers.) のファイルにあるCh14のCourse Person Professor SchedcleOfClasses Section Student Transcript TranscripEntry のクラス図を教えてください
C:\java\sample\d1>java sampled1l3 Exception in thread "main" java.lang.NoClassDefFoundError: sampled1l3 (wrong nam e: SampleD1L3) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source)
class Test { public static void main (String[] args) { try { PipedWriter pipedwriter = new PipedWriter(); PipedReader pipedreader = new PipedReader(pipedwriter); BufferedReader bufferedreader = new BufferedReader(pipedreader);
1 class a 2 public static int data = 100; 3 public static void main(String args[]){ 4 data++; 5 System.out.pritln("data is" + data); 6 } 7 }
1 class a 2 public static int data; 2 public static void func(){ 3 int data = 100; 4 } 5 public static void main(String args[]){ 6 data++; 7 System.out.println("data is" + data); 8 } 9 }
import java.util.Random; public class Test { public static void main(String args[]) {
String s = ""; for (int i=0;i<26;i++) { Random ran = new Random(); char n = (char)(ran.nextInt(26) + 65); s = s + n; } System.out.println(s); } } よろしくお願いします
public class Test { public static void main(String[] args) { TreeSet<Item> set = new TreeSet<Item>(); set.add(new Item("foo")); set.add(new Item("bar"));
for (Item item : set) { System.out.print(item); } } }
別スレでスルーされてしまい取り下げてきました。よろしかったらご教授お願いします オブジェクト指向で組みなおすにはどうしたらいいでしょうか?ちょっと長いです。すいません import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class shoot12 extends Applet implements Runnable, ActionListener { int x = 0; int dx = 10; int y = 10; int dy = 10; //飛行機の位置 int MX, MY; //マウスの位置 int y_bom = 10; //飛行機から発射される爆弾のy座標 int x_bom = 10; //飛行機から発射される爆弾のx座標 int bom_cnt = 0; //飛行機からの爆弾が砲台に命中した時の得点 int score = 0; //砲台からのミサイルが飛行機に命中した時の得点 int m_okflg = 0; //砲台からのミサイルが上の壁を通過したか int y_micyle; //砲台から発射されるミサイルのy座標 int x_micyle; //砲台から発射されるミサイルのx座標 static int st = 0; //OffScreenとOnScreenの切り替えようの変数 boolean flag = true; final String backg = "Clowd1.gif"; Thread MyThread; Image fire1; Image plane1; Image rocket1; Image Back; Graphics ofg; Image ofimg
704 :仕様書無しさん:2009/01/16(金) 14:49:38
public void init(){ fire1 = getImage(getDocumentBase(), "Fire1.gif"); plane1 = getImage(getDocumentBase(), "Plane1.gif"); rocket1 = getImage(getDocumentBase(), "Rocket1.gif"); Back = getImage(getDocumentBase(), backg); setLayout(new BorderLayout()); Panel pan1 = new Panel( ); Button btn1 = new Button("start"); btn1.addActionListener(this); pan1.add(btn1); Button btn2 = new Button("stop"); btn2.addActionListener(this); pan1.add(btn2); pan1.setBackground(Color.yellow); add(pan1,"South"); addMouseMotionListener(new myMousemove()); //マウスの移動 addMouseListener(new myMouseClick()); //マウスのクリックとミサイル ofimg = createImage(550, 500); //OffScreenのバッファ ofg = ofimg.getGraphics();} //マウスを左右に移動して砲台を動かす class myMousemove extends MouseMotionAdapter { public void mouseMoved(MouseEvent me) { MX = me.getX(); MY = me.getY();} } class myMouseClick extends MouseAdapter{ public void mouseClicked(MouseEvent me){ if (m_okflg == 0){ m_okflg = 1; //次のミサイルの発射を止めるため! x_micyle = me.getX() + 10; //砲台からのミサイルの移動 y_micyle = me.getY() - 10; } } }
705 :仕様書無しさん:2009/01/16(金) 14:51:54
↓ ↓ ハ,,ハ ↓ ( ゚ω゚ ) ↓ ↓
706 :仕様書無しさん:2009/01/16(金) 14:52:38
public void actionPerformed(ActionEvent e){ if (e.getActionCommand().equals("start")){ st = 1; MyThread = new Thread(this);//ゲームのスタート MyThread.start();} if (e.getActionCommand().equals("stop")){ MyThread = null;} } public void run(){ Thread nowThread = Thread.currentThread(); while (MyThread == nowThread){ try{ Thread.sleep(200);} catch (InterruptedException e){ break; } repaint();} } public void paint(Graphics g){ //飛行機の位置が画面の左右の壁を超えたとき! if (x <= 0 || x >= getSize().width) x = 0; //飛行機を初期位置に設定する ofg.drawImage(Back, 0, 0, this); if (st == 1){ ofg.drawImage(plane1, x, y, this);//飛行機の表示 ofg.drawImage(rocket1, MX, 400, 32, 32, this);//マウス移動による砲台の表示 ofg.setColor(Color.red); //投下の爆弾の赤色 ofg.fillRect(x_bom, y_bom, 4, 10);} //OnScreenへ表示する! g.drawImage(ofimg, 0, 0, this);//投下の爆弾の表示 x = x + dx;//飛行機の位置 y_bom += 30;//爆弾の加速 //新しい爆弾の表示
String s = aPlayers[i]; // i = 0 のとき "sato" Player p = new Player(s); // 上で取得した名前を引数にしたPlayerクラスをつくる team.registPlayer(i, p); // 「index=0」 => 「"sato"ってPlayer」 で登録する
class Animal {} class Dog extends Animal {} class Poodle extends Dog {}
class Test <T extends Animal> { public void func(List<? extends T> arg) { } }
class Main { public static void main(String[] args) { List<Poodle> list = new ArrayList<Poodle>(); list.add(new Poodle()); new Test<Dog>().func(list); } }
class Super { static int DEFAULT_SIZE = 10; int[] array; Super(){ array = new int[DEFAULT_SIZE]; } } class Sub extends Super { static { DEFAULT_SIZE = 20; } }
879 :872:2009/11/13(金) 22:26:12
>>878 続き これは、 new Super()とした場合は要素数10の配列を保持するインスタンスができ、 new Sub()とした場合は要素数20の(ry ができると期待するコードですが 実際はそうはなりません。DEFAULT_SIZEの実体はSuper.DEFAULT_SIZEの唯一つだからです。 そこで、サブクラスで初期値のみを変えられるようにするためにstatic int DEFAULT_SIZEを int getDefaultSize()などというメソッドに置き換えようと考えました。 そして上のコードを以下のように書き換えれば期待通りの設計にすることができます。
class Super { int[] array; Super(){ array = new int[getDefaultSize()]; } int getDefaultSize(){return 10;} } class Sub extends Super { int getDefaultSize(){return 20;} }
880 :仕様書無しさん:2009/11/14(土) 22:58:25
class Super { int[] array; Super(){ this(10); } Super(int DEFAULT_SIZE) { array = new int[DEFAULT_SIZE]; } } class Sub extends Super { Sub() { super(20); } }
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission org.apache.commons.logging.LogFactory.HashtableImpl read) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPropertyAccess(Unknown Source) at java.lang.System.getProperty(Unknown Source) at org.apache.commons.logging.LogFactory.createFactoryStore(LogFactory.java:320) at org.apache.commons.logging.LogFactory.<clinit>(LogFactory.java:1725)