创建Java中的一个超级简单的小程序表 [英] creating a super simple table applet in java

查看:261
本文介绍了创建Java中的一个超级简单的小程序表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个显示一个简单的表,没有头或其他装饰的小程序。会有人这么好心给我的code这个?我发现所有的例子都没有编译或已包括我并不需要额外的功能。一个简单的2×2表空细胞和无头就是我要找的。感谢所有提前...

I'm trying to create an applet which displays a simple table with no headers or other decoration. Could anyone be so kind as to show me the code for this? All the examples I've found haven't compiled or have included extra features which I don't need. A simple 2 x 2 table with empty cells and no headers is what I'm looking for. Thanks to all in advance...

code为skaffman:

Code for skaffman:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class danTeamProject extends Applet implements ActionListener
{
char[][] charValues = new char[10][10];
danTable aTable;
boolean allowUserInput = false;

public void init()
{
	Button BtnStart = new Button("Start");
	BtnStart.addActionListener((ActionListener)this);	//cast
	this.add(BtnStart);	//add action listener to button


	aTable = new danTable();
	aTable.setVisible(true);


}

public void paint(Graphics g)
{
    g.setColor(Color.black);
    aTable.draw(g);
}
public void actionPerformed(ActionEvent arg0)
{

}

}

import java.awt.*;
import java.util.*;
import javax.swing.*;

public class danTable extends JPanel
{



public danTable()
{

 // Create with initial data
Object[][] cellData = {
    {"row1-col1", "row1-col2"},
    {"row2-col1", "row2-col2"}};
String[] columnNames = {"col1", "col2"};

JTable table = new JTable(cellData, columnNames);

}

}

推荐答案

我对C您发布修改$ C $。

I have modified the code you posted.

阅读它需要多次,直到你明白它做什么。又见编码约定(括号和变量的命名)

Read it as many times as needed until you understand what it does. See also the coding conventions ( the brackets and the naming of the variables )

我并没有太多的改变,虽然,我只是使它运行。

I didn't change too much though, I just make it run.

要特别注意你的code,这之间的差异(它们不是太多,但)随意问如有疑问

Pay special attention to the difference between your code and this one ( they are not too much though ) Feel free to ask in case of doubts

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DanTeamProject extends Applet {
    char[][] charValues = new char[10][10];
    DanTable aTable;
    boolean allowUserInput = false;

    public void init()	{
    	Button btnStart = new Button("Start");
    	this.add(btnStart);
    	aTable = new DanTable();
    	this.add( aTable );
    }
}

class DanTable extends JPanel {
    public DanTable() {
        Object[][] cellData = {
            {"row1-col1", "row1-col2"},
            {"row2-col1", "row2-col2"}};
        String[] columnNames = {"col1", "col2"};
        add(  new JTable(cellData, columnNames) ) ;
    }
}

下面是用来查看的HTML

Here's the HTML used to view it

<applet code="DanTeamProject.class" width=100 height=140></applet>

下面是输出:

这篇关于创建Java中的一个超级简单的小程序表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆