本文整理匯總了Java中java.awt.List.add方法的典型用法代碼示例。如果您正苦於以下問題:Java List.add方法的具體用法?Java List.add怎麽用?Java List.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.List
的用法示例。
在下文中一共展示了List.add方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: m
import java.awt.List; //導入方法依賴的package包/類
private MethodTree m(TreeMaker make) {
// create method modifiers
ModifiersTree parMods = make.Modifiers(Collections.<Modifier>emptySet(), Collections.<AnnotationTree>emptyList());
// create parameters
VariableTree par1 = make.Variable(parMods, "a", make.PrimitiveType(TypeKind.INT), null);
VariableTree par2 = make.Variable(parMods, "b", make.PrimitiveType(TypeKind.FLOAT), null);
List<VariableTree> parList = new ArrayList<VariableTree>(2);
parList.add(par1);
parList.add(par2);
// create method
MethodTree newMethod = make.Method(
make.Modifiers(
Collections.singleton(Modifier.PUBLIC), // modifiers
Collections.<AnnotationTree>emptyList() // annotations
), // modifiers and annotations
"newlyCreatedMethod", // name
make.PrimitiveType(TypeKind.VOID), // return type
Collections.<TypeParameterTree>emptyList(), // type parameters for parameters
parList, // parameters
Collections.singletonList(make.Identifier("java.io.IOException")), // throws
make.Block(Collections.<StatementTree>emptyList(), false), // empty statement block
null // default value - not applicable here, used by annotations
);
return newMethod;
}
示例2: main
import java.awt.List; //導入方法依賴的package包/類
public static void main(final String[] args) throws HeadlessException {
final Frame frame = new Frame("Test Frame");
final List list = new List();
frame.setSize(300, 200);
list.add(ITEM_NAME);
list.select(0);
frame.add(list);
frame.validate();
frame.setVisible(true);
sleep();
if (!ITEM_NAME.equals(list.getSelectedItem())) {
throw new RuntimeException("List item not selected item.");
}
list.removeAll();
frame.dispose();
}
示例3: ActionEventTest
import java.awt.List; //導入方法依賴的package包/類
public ActionEventTest() {
try {
robot = new Robot();
robot.setAutoDelay(100);
robot.setAutoWaitForIdle(true);
} catch(AWTException e) {
throw new RuntimeException(e.getMessage());
}
list = new List(1, false);
list.add("0");
add(list);
setSize(400,400);
setLayout(new FlowLayout());
pack();
setVisible(true);
}
示例4: ItemEventTest
import java.awt.List; //導入方法依賴的package包/類
public ItemEventTest()
{
try {
robot = new Robot();
} catch(AWTException e) {
throw new RuntimeException(e.getMessage());
}
expectedSelectionOrder = "01230123";
list = new List(4, true);
list.add("0");
list.add("1");
list.add("2");
list.add("3");
add(list);
setSize(400,400);
setLayout(new FlowLayout());
pack();
setVisible(true);
robot.waitForIdle();
}
示例5: ActionEventTest
import java.awt.List; //導入方法依賴的package包/類
public ActionEventTest() {
try {
robot = new Robot();
} catch(AWTException e) {
throw new RuntimeException(e.getMessage());
}
list = new List(1, false);
list.add("0");
add(list);
setSize(400,400);
setLayout(new FlowLayout());
pack();
setVisible(true);
robot.waitForIdle();
}
示例6: init
import java.awt.List; //導入方法依賴的package包/類
public void init ()
{
initted = true;
Panel p = new Panel ();
p.setLayout (new GridLayout (3, 1));
List l = new List (5, true);
for (int i = 0; i < 10; i++)
l.add ("List item " + i);
p.add (l);
add (p, "Center");
Button cb = new Button ("Close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add (cb, "South");
setTitle ("List");
pack();
}
示例7: add
import java.awt.List; //導入方法依賴的package包/類
private static List<RangeMarker> add(DocumentEx document, int... offsets) {
List<RangeMarker> result = new ArrayList<RangeMarker>();
for (int i=0; i<offsets.length; i+=2) {
int start = offsets[i];
int end = offsets[i+1];
RangeMarker m = document.createRangeMarker(start, end);
result.add(m);
}
return result;
}
示例8: testAddConstructor
import java.awt.List; //導入方法依賴的package包/類
public void testAddConstructor() throws Exception {
testFile = new File(getWorkDir(), "Test.java");
TestUtilities.copyStringToFile(testFile,
"package hierbas.del.litoral;\n\n" +
"public class Test {\n" +
" \n" +
" String prefix;\n" +
" \n" +
" public void method() {\n" +
" }\n" +
" \n" +
"}\n"
);
String golden =
"package hierbas.del.litoral;\n\n" +
"public class Test {\n" +
" \n" +
" String prefix;\n" +
"\n" +
" public Test(boolean prefix) {\n" +
" }\n" +
" \n" +
" public void method() {\n" +
" }\n" +
" \n" +
"}\n";
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
for (Tree typeDecl : cut.getTypeDecls()) {
// ensure that it is correct type declaration, i.e. class
if (TreeUtilities.CLASS_TREE_KINDS.contains(typeDecl.getKind())) {
ClassTree classTree = (ClassTree) typeDecl;
ModifiersTree mods = make.Modifiers(EnumSet.of(Modifier.PUBLIC));
List<VariableTree> arguments = new ArrayList<VariableTree>();
arguments.add(make.Variable(
make.Modifiers(EnumSet.noneOf(Modifier.class)),
"prefix",
make.PrimitiveType(TypeKind.BOOLEAN), null)
);
MethodTree constructor = make.Method(
mods,
"<init>",
null,
Collections.<TypeParameterTree> emptyList(),
arguments,
Collections.<ExpressionTree>emptyList(),
make.Block(Collections.<StatementTree>emptyList(), false),
null
);
ClassTree copy = make.insertClassMember(classTree, 2, constructor);
workingCopy.rewrite(classTree, copy);
}
}
}
};
src.runModificationTask(task).commit();
String res = TestUtilities.copyFileToString(testFile);
System.err.println(res);
assertEquals(golden, res);
}
示例9: createGUI
import java.awt.List; //導入方法依賴的package包/類
public void createGUI() {
frame = new Frame();
frame.setTitle("ExtendedModifiersTest");
frame.setLayout(new GridLayout(1, 6));
button = new Button();
button.addKeyListener(this);
frame.add(button);
buttonLW = new LWButton();
buttonLW.addKeyListener(this);
frame.add(buttonLW);
textField = new TextField(5);
textField.addKeyListener(this);
frame.add(textField);
textArea = new TextArea(5, 5);
textArea.addKeyListener(this);
frame.add(textArea);
list = new List();
for (int i = 1; i <= 5; ++i) {
list.add("item " + i);
}
list.addKeyListener(this);
frame.add(list);
listLW = new LWList();
for (int i = 1; i <= 5; ++i) {
listLW.add("item " + i);
}
listLW.addKeyListener(this);
frame.add(listLW);
frame.setBackground(Color.gray);
frame.setSize(500, 100);
frame.setVisible(true);
frame.toFront();
}
示例10: handleChoice
import java.awt.List; //導入方法依賴的package包/類
protected synchronized void handleChoice(ChoiceCallback c)
{
Frame ownerFrame = new Frame();
Dialog dialog = new Dialog(ownerFrame);
String[] choices = c.getChoices();
dialog.setTitle(c.getPrompt());
Label label = new Label(c.getPrompt());
List list = new List(Math.min(5, choices.length),
c.allowMultipleSelections());
Panel buttons = new Panel();
Button ok = new Button(messages.getString("callback.ok"));
ok.setActionCommand(ACTION_OK);
ok.addActionListener(this);
Button cancel = new Button(messages.getString("callback.cancel"));
cancel.setActionCommand(ACTION_CANCEL);
cancel.addActionListener(this);
for (int i = 0; i < choices.length; i++)
{
list.add(choices[i]);
}
if (c.getDefaultChoice() >= 0 && c.getDefaultChoice() < choices.length)
{
list.select(c.getDefaultChoice());
}
dialog.setLayout(new BorderLayout());
dialog.add(label, BorderLayout.NORTH);
dialog.add(list, BorderLayout.CENTER);
buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttons.add(cancel);
buttons.add(ok);
dialog.add(buttons, BorderLayout.SOUTH);
dialog.pack();
dialog.show();
try { wait(); }
catch (InterruptedException ie) { }
if (actionCommand.equals(ACTION_OK))
{
if (c.allowMultipleSelections())
{
c.setSelectedIndexes(list.getSelectedIndexes());
}
else
{
c.setSelectedIndex(list.getSelectedIndex());
}
}
dialog.dispose();
ownerFrame.dispose();
}