我的JMenuBar上的ActionListener需要一些帮助.
没有错误; 但是每次单击JMenuItem时,它都会触发与JMenuItem关联的所有操作.我的问题是:我在ActionListener代码中做得对吗?我对ActionListener类不太确定.我正在尝试将我的ActionListener与Button逻辑分开.
如果有人对我可能做错了什么有任何想法,请指出.
这是我的代码:
package MenuBar;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class SimpleMenuBar{
private static final LayoutManager grid = new GridLayout(0, 1);
public JMenuBar MenuBar;
public JMenu MenuFile, MenuEdit, MenuOption;
public JMenuItem ItemNew, ItemOpen, ItemSave, ItemExit, ItemCopy, ItemCut, ItemPaste;
ButtonGroup direction;
JRadioButtonMenuItem forwardradio, backwardradio;
JCheckBoxMenuItem CheckCase;
String input = null;
public void Design()
{
JFrame frame = new JFrame("Simple Menubar");
frame.setSize(320, 320);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
MenuBar = new JMenuBar();
frame.setJMenuBar(MenuBar);
MenuBar.setLayout(grid);
//Menus
MenuFile = new JMenu("File");
MenuFile.setMnemonic(KeyEvent.VK_F);
MenuBar.add(MenuFile); …Run Code Online (Sandbox Code Playgroud) 我想从Jtable中获取值,并且我使用getvalueat尝试了它但是每当我尝试从JTable获取值时它只从所选行的第一列获取值,我需要获取所有值来自我选择的Jtable.你能帮我解决这个问题
here is my code:
class GetTableValue implements ActionListener{
public void actionPerformed(ActionEvent e){
AbstractButton button = (AbstractButton)e.getSource();
if(e.getActionCommand().equals(button.getActionCommand)){
int row = table.getSelectedRow();
int col = table.getSelectedColumn();
Object data = (Object)table.getValueAt(row, col);
JOptionPane.showMessageDialog(null, data);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的动作事件,其中所选表的值显示在JOptionPane中,不幸的是它只显示一个值(这是您已选择的值)而不是整行.
这段代码是我的Jbutton调用action事件的(我已经从JTable中排除了我的代码,因为它从我的数据库中获取Jtable值)
ActionListener tableAction = new GetTableValue();
buttonEdit = new JButton("EDIT");
buttonEdit.addActionListener(tableAction);
Run Code Online (Sandbox Code Playgroud)
代码简单明了,我还搜索G先生(google)关于获取行的一个很好的教程,遗憾的是没有一个很好的教程来获取Jtable值(每行).
我在使用oracle外部表时遇到问题,我有一个文本文件将有50多个不必要的列,现在我想从文本文件中选择几列到我的外部表。
create table tmpdc_ticket(
SERVICE_ID CHAR(144),
SERVICE_TYPE CHAR(50),
CUSTOMER_NAME CHAR(200),
TELEPHONE_NO CHAR(144),
ACCOUNT_NUMBER CHAR(144),
FAULT_STATUS CHAR(50),
BUSINESS_GROUP CHAR(100)
)
organization external(
type oracle_loader
default directory sample_directory
access parameters(
records delimited by newline
nologfile
skip 1
fields terminated by '|'
missing field values are null
(SERVICE_ID CHAR(144),
SERVICE_TYPE CHAR(50),
CUSTOMER_NAME CHAR(200),
TELEPHONE_NO CHAR(144),
ACCOUNT_NUMBER CHAR(144),
FAULT_STATUS CHAR(50),
BUSINESS_GROUP CHAR(100)
)
)
location(sample_directory:'sample_file.txt')
)
reject limit 1
noparallel
nomonitoring;
Run Code Online (Sandbox Code Playgroud)
但是,似乎oracle_loader正在从文本文件的第一列进行插入。是否有可能像文本文件中的第3列一样已经获取?