真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java刪除一整行代碼 java刪除文件中指定行

java怎么實(shí)現(xiàn)表格的行刪除

java中表格的刪除是通過事件監(jiān)控來實(shí)現(xiàn)的,示例代碼如下:

米脂ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.JTextField;

import javax.swing.ListSelectionModel;

import javax.swing.table.DefaultTableModel;

//維護(hù)表格

public class JTableDefaultTableModelTest extends JFrame{

private DefaultTableModel tableModel; //表格模型對(duì)象

private JTable table;

private JTextField aTextField;

private JTextField bTextField;

public JTableDefaultTableModelTest()

{

super();

setTitle("表格");

setBounds(100,100,500,400);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

String[] columnNames = {"A","B"}; //列名

String [][]tableVales={{"A1","B1"},{"A2","B2"},{"A3","B3"},{"A4","B4"},{"A5","B5"}}; //數(shù)據(jù)

tableModel = new DefaultTableModel(tableVales,columnNames);

table = new JTable(tableModel);

JScrollPane scrollPane = new JScrollPane(table); //支持滾動(dòng)

getContentPane().add(scrollPane,BorderLayout.CENTER);

//jdk1.6

//排序:

//table.setRowSorter(new TableRowSorter(tableModel));

table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //單選

table.addMouseListener(new MouseAdapter(){ //鼠標(biāo)事件

public void mouseClicked(MouseEvent e){

int selectedRow = table.getSelectedRow(); //獲得選中行索引

Object oa = tableModel.getValueAt(selectedRow, 0);

Object ob = tableModel.getValueAt(selectedRow, 1);

aTextField.setText(oa.toString()); //給文本框賦值

bTextField.setText(ob.toString());

}

});

scrollPane.setViewportView(table);

final JPanel panel = new JPanel();

getContentPane().add(panel,BorderLayout.SOUTH);

panel.add(new JLabel("A: "));

aTextField = new JTextField("A4",10);

panel.add(aTextField);

panel.add(new JLabel("B: "));

bTextField = new JTextField("B4",10);

panel.add(bTextField);

final JButton addButton = new JButton("添加"); //添加按鈕

addButton.addActionListener(new ActionListener(){//添加事件

public void actionPerformed(ActionEvent e){

String []rowValues = {aTextField.getText(),bTextField.getText()};

tableModel.addRow(rowValues); //添加一行

int rowCount = table.getRowCount() +1; //行數(shù)加上1

aTextField.setText("A"+rowCount);

bTextField.setText("B"+rowCount);

}

});

panel.add(addButton);

final JButton updateButton = new JButton("修改"); //修改按鈕

updateButton.addActionListener(new ActionListener(){//添加事件

public void actionPerformed(ActionEvent e){

int selectedRow = table.getSelectedRow();//獲得選中行的索引

if(selectedRow!= -1) //是否存在選中行

{

//修改指定的值:

tableModel.setValueAt(aTextField.getText(), selectedRow, 0);

tableModel.setValueAt(bTextField.getText(), selectedRow, 1);

//table.setValueAt(arg0, arg1, arg2)

}

}

});

panel.add(updateButton);

final JButton delButton = new JButton("刪除");

delButton.addActionListener(new ActionListener(){//添加事件

public void actionPerformed(ActionEvent e){

int selectedRow = table.getSelectedRow();//獲得選中行的索引

if(selectedRow!=-1) //存在選中行

{

tableModel.removeRow(selectedRow); //刪除行

}

}

});

panel.add(delButton);

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

JTableDefaultTableModelTest jTableDefaultTableModelTest = new JTableDefaultTableModelTest();

jTableDefaultTableModelTest.setVisible(true);

}

}

刪除二維數(shù)組中的滿行 用java編寫代碼

//刪除元素為全1的行,不知道是不是你要的功能

public class Demo {

public static void main(String[] args) {

int[][] a={

{0,0,0,0,0},

{0,1,0,1,0},

{1,1,1,1,1},

{1,1,1,1,1},

{0,1,1,1,1},

{1,1,1,1,1}

};

len=a.length;

System.out.println("刪除滿行前:");

output(a);

cutFullLine(a);

System.out.println("刪除滿行后:");

output(a);

}

static void output(int[][] a) {

for(int i=0;ilen;i++) {

for(int j=0;ja[i].length;j++) {

System.out.print(""+a[i][j]+" ");

}

System.out.println();

}

}

static void cutFullLine(int[][] a) {

for(int i=0;ilen;) {

if(isFull(a[i])) {

for(int j=i+1;jlen;j++) {

a[j-1]=a[j];

len--;

}

}

else {

i++;

}

}

}

static boolean isFull(int[] line) {

boolean r=true;

for(int i=0;iline.length;i++) {

if(1!=line[i]) {

r=false;

break;

}

}

return r;

}

static int len;

}

java 文件中刪除一行(或某個(gè)字符)

用“”替換文件中的內(nèi)容達(dá)到刪除目的

import?java.io.InputStream;

import?java.io.BufferedReader;

import?java.io.BufferedWriter;

import?java.io.FileReader;

import?java.io.FileWriter;

import?java.util.Scanner;

import?java.io.FileNotFoundException;

import?java.io.IOException;

public?class?zifutihuan

{

protected?static?void?rep(String?ch)

{

BufferedReader?bis?=?null;

FileWriter?bos?=?null;

String?s?=?null;

???try

???{?

?bis?=?new?BufferedReader(new?FileReader("1.txt"));

??bos?=?new?FileWriter("2.txt");

while(null?!=?(s?=?bis.readLine()))

???{

??? s?=?s.replaceAll(ch,"");

??? System.out.println(s);

??? s=?s+"\r\n";

bos.write(s);

??? }

?bos.close();

??bis.close();

??s?=?null;

}

catch(FileNotFoundException?e)

{

System.out.println("未找到文件\n");

}

catch(IOException?ee)

{

System.out.println("aaa");

}

}

public?static?void?main(String?args[])

{?

rep("123");

}

}


新聞標(biāo)題:java刪除一整行代碼 java刪除文件中指定行
標(biāo)題URL:http://weahome.cn/article/dddpdic.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部